-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptCrashFor flagging bugs which are compiler or service crashes or unclean exits, rather than bad outputFor flagging bugs which are compiler or service crashes or unclean exits, rather than bad output
Milestone
Description
TypeScript Version: 3.7.0-beta
Search Terms:
Optional chaining, CallChain
Code
function find<T>(fun: (_: T) => boolean) {
return (arr: T[]) => arr.find(fun)
}
type Item = {
label: string
id: number
}
const items: Item[] = [
{ label: 'one', id: 1 },
{ label: 'two', id: 2
]
const upperCasedlabel = items.find(i => i.id === 1)?.label.toUpperCase() // ONE ✅
// despite the fact that I don't have any ts warning/error, the expression below fails at runtime.
// 👇 does not work, getting this error -> Debug Failure. False expression: Cannot update a CallChain using updateCall. Use updateCallChain instead.
const altUpperCasedlabel = find<Item>(i => i.id === 1)(items)?.label.toUpperCase() ❌
// When I break this into two steps, it works
const maybeItem = find<Item>(i => i.id === 1)(items)
const altUpperCasedlabel = maybeItem?.label.toUpperCase() // ONE ✅
// This also works
const altLabel = find<Item>(i => i.id === 1)(items)?.label // one ✅Expected behavior:
I'm expecting the first expression altLabel to work, without the need to break the process into two steps
Actual behavior:
Getting an error, Debug Failure. False expression: Cannot update a CallChain using updateCall. Use updateCallChain instead.
Playground Link:
Related Issues:
ryanburr and lake2
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptCrashFor flagging bugs which are compiler or service crashes or unclean exits, rather than bad outputFor flagging bugs which are compiler or service crashes or unclean exits, rather than bad output