Closed
Description
TypeScript Version: 3.3.2 (tried latest next
and issue still existed)
Search Terms:
charCodeAt, isLateBoundName
Code
export interface A { type: 'a' }
export interface B { type: 'b' }
export type AB = A | B
const itemId = 'some-id'
// --- test on first level ---
const items: { [id: string]: AB } = {}
const { [itemId]: itemOk1 } = items
typeof itemOk1 // pass
// --- test on second level ---
interface ObjWithItems {
items: {[s: string]: AB}
}
const objWithItems: ObjWithItems = { items: {}}
const itemOk2 = objWithItems.items[itemId]
typeof itemOk2 // pass
const {
items: { [itemId]: itemWithTSError } = {} /*happens when default value is provided*/
} = objWithItems
// in order to re-produce the error, uncomment next line:
// typeof itemWithTSError // :(
// will result in:
// Error from compilation: TypeError: Cannot read property 'charCodeAt' of undefined TypeError: Cannot read property 'charCodeAt' of undefined
Expected behavior:
No crash.
Actual behavior:
Crashes with TypeError mid-compilation:
TypeError: Cannot read property 'charCodeAt' of undefined
at isLateBoundName (...\typescript.js:36537:25)
at createUnionOrIntersectionProperty (...\typescript.js:37624:42)
at getUnionOrIntersectionProperty (...\typescript.js:37690:28)
at getPropertyOfUnionOrIntersectionType (...\typescript.js:37698:28)
at getPropertyOfType (...\typescript.js:37731:24)
at getTypeOfPropertyOfType (...\typescript.js:35017:24)
at getTypeOfDestructuredProperty (...\typescript.js:44548:45)
at getInitialTypeOfBindingElement (...\typescript.js:44613:17)
at getInitialType (...\typescript.js:44641:17)
at getInitialOrAssignedType (...\typescript.js:44645:17)
Related Issues:
Looks similar to #26321