Skip to content

Inconsistent behaviour of enum.  #50507

Closed
@pociej

Description

@pociej

πŸ”Ž Search Terms

wrong enum behaviour numeric enum wrong check inconsistent enum behaviour

πŸ•— Version & Regression Information

I see it in all versions of ts

⏯ Playground Link

https://tsplay.dev/N9PO8w

πŸ’» Code

enum myEnum {
    a = 'a',
    b = 'b',
}


enum extendedEnum {
    a = "a", 
    b = "b", 
    //use any number here, 11 is random value 
    c = 11, 
}


//use any number here, 48 is random value 

const returnsMyEnum = function() : myEnum {
    return 48;  
}

const returnMyExtendedEnum = function() : extendedEnum {
    return 48; 
}

πŸ™ Actual behavior

Only returnsMyEnum gives typescript error.

πŸ™‚ Expected behavior

Both functions are wrong.

Activity

jcalz

jcalz commented on Aug 29, 2022

@jcalz
Contributor

Duplicate of #26362

fatcerberus

fatcerberus commented on Aug 30, 2022

@fatcerberus
// use any number here, 11 is random value 
c = 11,

I’m suddenly reminded of this
https://xkcd.com/221/

typescript-bot

typescript-bot commented on Sep 1, 2022

@typescript-bot
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @jcalz@pociej@fatcerberus@RyanCavanaugh@typescript-bot

        Issue actions

          Inconsistent behaviour of enum. Β· Issue #50507 Β· microsoft/TypeScript