Skip to content

Fault in tsc --noEmit on mixed up params in complex functionΒ #49966

Closed
@llaenowyd

Description

@llaenowyd

Bug Report

πŸ”Ž Search Terms

fault
Object
parameter
symbol
cached
type
differs
assigned

πŸ•— Version & Regression Information

  • This is a crash in tsc version 4.7.4

⏯ Playground Link

Please find an example reproduction here

πŸ’» Code

This is correct and passes tsc --noEmit as expected! πŸŽ‰

  useRecoilCallback(({ set }) => (i: number, nextSymbol: string) => {

This is incorrect but instead of printing a diagnostic tsc faults. Unfortunately without a good diagnostic.

  useRecoilCallback((i: number) => ({ set }, nextVal: string) => {})

πŸ™ Actual behavior

$ tsc --noEmit
/src/tsc-fault-useRecoilCallback\node_modules\typescript\lib\tsc.js:96888
                throw e;
                ^

Error: Debug Failure. Expected [object Object] === [object Object]. Parameter symbol already has a cached type which differs from newly assigned type
    at assignParameterType (/src/tsc-fault-useRecoilCallback\node_modules\typescript\lib\tsc.js:64862:26)
    at assignContextualParameterTypes (/src/tsc-fault-useRecoilCallback\node_modules\typescript\lib\tsc.js:64827:21)
    at contextuallyCheckFunctionExpressionOrObjectLiteralMethod (/src/tsc-fault-useRecoilCallback\node_modules\typescript\lib\tsc.js:65229:29)
    at checkFunctionExpressionOrObjectLiteralMethod (/src/tsc-fault-useRecoilCallback\node_modules\typescript\lib\tsc.js:65208:13)
    at checkExpressionWorker (/src/tsc-fault-useRecoilCallback\node_modules\typescript\lib\tsc.js:66805:28)
    at checkExpression (/src/tsc-fault-useRecoilCallback\node_modules\typescript\lib\tsc.js:66707:38)
    at checkExpressionCached (/src/tsc-fault-useRecoilCallback\node_modules\typescript\lib\tsc.js:66411:24)
    at getReturnTypeFromBody (/src/tsc-fault-useRecoilCallback\node_modules\typescript\lib\tsc.js:64931:30)
    at contextuallyCheckFunctionExpressionOrObjectLiteralMethod (/src/tsc-fault-useRecoilCallback\node_modules\typescript\lib\tsc.js:65236:42)
    at checkFunctionExpressionOrObjectLiteralMethod (/src/tsc-fault-useRecoilCallback\node_modules\typescript\lib\tsc.js:65208:13)

Node.js v18.2.0

πŸ™‚ Expected behavior

Normally tsc should print a diagnostic instead of failing its assertion.

I bet it's because these functions have complex types.

Here in a simple case with

export const f = (a: string, b: number) => {}
f(123, 'abc')

then it behaves like this

$ tsc --noEmit
/src/simpleParamsError.ts(2,3): error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions