- Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
Description
TypeScript Version: 2.3.0 RC
I'm observing some strange type behavior. Consider the following snippet.
type myType = "MY_TYPE"; const myType: myType = "MY_TYPE"; const foo = myType; const bar = { baz: foo };The type of foo and baz are both "MY_TYPE" as expected.
However using this strEnum function as described here which, based on my understanding, should be doing the same thing as the above code, results in something different:
function strEnum<T extends string>(o: Array<T>): {[K in T]: K} { return o.reduce((res, key) => { res[key] = key; return res; }, Object.create(null)); } const myTypeEnum = strEnum(["MY_TYPE"]) const foo = myTypeEnum.MY_TYPE; const bar = { baz: foo };Here, foo is detected to be type "MY_TYPE", but baz is recognized as type string
Am I doing something wrong? Is this expected behavior?
Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug