1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
=== tests/cases/compiler/crashInGetTextOfComputedPropertyName.ts ===
// https://github.com/Microsoft/TypeScript/issues/29006
export interface A { type: 'a' }
>type : "a"
export interface B { type: 'b' }
>type : "b"
export type AB = A | B
>AB : A | B
const itemId = 'some-id'
>itemId : "some-id"
>'some-id' : "some-id"
// --- test on first level ---
const items: { [id: string]: AB } = {}
>items : { [id: string]: AB; }
>id : string
>{} : {}
const { [itemId]: itemOk1 } = items
>itemId : "some-id"
>itemOk1 : AB
>items : { [id: string]: AB; }
typeof itemOk1 // pass
>typeof itemOk1 : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>itemOk1 : AB
// --- test on second level ---
interface ObjWithItems {
items: {[s: string]: AB}
>items : { [s: string]: AB; }
>s : string
}
const objWithItems: ObjWithItems = { items: {}}
>objWithItems : ObjWithItems
>{ items: {}} : { items: {}; }
>items : {}
>{} : {}
const itemOk2 = objWithItems.items[itemId]
>itemOk2 : AB
>objWithItems.items[itemId] : AB
>objWithItems.items : { [s: string]: AB; }
>objWithItems : ObjWithItems
>items : { [s: string]: AB; }
>itemId : "some-id"
typeof itemOk2 // pass
>typeof itemOk2 : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>itemOk2 : AB
const {
items: { [itemId]: itemWithTSError } = {} /*happens when default value is provided*/
>items : any
>itemId : "some-id"
>itemWithTSError : AB
>{} : {}
} = objWithItems
>objWithItems : ObjWithItems
// in order to re-produce the error, uncomment next line:
typeof itemWithTSError // :(
>typeof itemWithTSError : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>itemWithTSError : AB
// will result in:
// Error from compilation: TypeError: Cannot read property 'charCodeAt' of undefined TypeError: Cannot read property 'charCodeAt' of undefined
|