Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
llaenowyd opened this issue Jul 20, 2022 · 3 comments
Closed

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

llaenowyd opened this issue Jul 20, 2022 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@llaenowyd
Copy link

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'.
@MartinJohns
Copy link
Contributor

Duplicate of #49383.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jul 20, 2022
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@TrySpace
Copy link

This is the most recent open issue on this: #50773

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

5 participants