Closed
Description
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) => {
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'.