TypeScript/tests/baselines/reference/enumIndexer.types
Wesley Wigham 0dbad04c3f
Distribute indexed accesses when simplifying them (#26281)
* unknownify accesses

* Move to simplify to break less with fewer changes

* Accept baselines for now

* Always propegate any as an index type

* Fix flow control in the presence of simplifiable types

* Add spy repro from #25181

* Retain errorType when it is used as a marker for the lack of a constraint

* Small refinement

* Add new test

* Move most potentially recursive types from isIdenticalTo into structuredTypeRelatedTo to match the non-identity relations

* Fix nits

* Doesnt need to be undefineable at all
2018-08-27 13:32:01 -07:00

40 lines
1.3 KiB
Text

=== tests/cases/compiler/enumIndexer.ts ===
enum MyEnumType {
>MyEnumType : MyEnumType
foo, bar
>foo : MyEnumType.foo
>bar : MyEnumType.bar
}
var _arr = [{ key: 'foo' }, { key: 'bar' }]
>_arr : { key: string; }[]
>[{ key: 'foo' }, { key: 'bar' }] : { key: string; }[]
>{ key: 'foo' } : { key: string; }
>key : string
>'foo' : "foo"
>{ key: 'bar' } : { key: string; }
>key : string
>'bar' : "bar"
var enumValue = MyEnumType.foo;
>enumValue : MyEnumType
>MyEnumType.foo : MyEnumType.foo
>MyEnumType : typeof MyEnumType
>foo : MyEnumType.foo
var x = _arr.map(o => MyEnumType[o.key] === enumValue); // these are not same type
>x : boolean[]
>_arr.map(o => MyEnumType[o.key] === enumValue) : boolean[]
>_arr.map : <U>(callbackfn: (value: { key: string; }, index: number, array: { key: string; }[]) => U, thisArg?: any) => U[]
>_arr : { key: string; }[]
>map : <U>(callbackfn: (value: { key: string; }, index: number, array: { key: string; }[]) => U, thisArg?: any) => U[]
>o => MyEnumType[o.key] === enumValue : (o: { key: string; }) => boolean
>o : { key: string; }
>MyEnumType[o.key] === enumValue : boolean
>MyEnumType[o.key] : error
>MyEnumType : typeof MyEnumType
>o.key : string
>o : { key: string; }
>key : string
>enumValue : MyEnumType