Skip to content

Optional chaining, CallChain error #33744

@acd02

Description

@acd02

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:

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptCrashFor flagging bugs which are compiler or service crashes or unclean exits, rather than bad output

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions