Skip to content

Inconsistent behaviour of enum. οΏ½?#50507

@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.

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

    Issue actions