Skip to content
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

Crash on 5.4.0-dev.20231206 #56688

Closed
ArnaudBarre opened this issue Dec 6, 2023 · 6 comments · Fixed by #56711
Closed

Crash on 5.4.0-dev.20231206 #56688

ArnaudBarre opened this issue Dec 6, 2023 · 6 comments · Fixed by #56711
Labels
Bug A bug in TypeScript
Milestone

Comments

@ArnaudBarre
Copy link

🔎 Search Terms

🕗 Version & Regression Information

It's working on 5.3
Here is the stacktrace, I hope it helps, I don't really have time to disect which part my codebase triggers this. Feel free to close if this not enough to understand the regression

TypeError: Cannot read properties of undefined (reading '0')
   at removeConstrainedTypeVariables (/Users/arnaud/git/carbon-calculator/node_modules/typescript/lib/tsc.js:57118:33)
   at getUnionTypeWorker (/Users/arnaud/git/carbon-calculator/node_modules/typescript/lib/tsc.js:57215:9)
   at getUnionType (/Users/arnaud/git/carbon-calculator/node_modules/typescript/lib/tsc.js:57194:12)
   at createJsxAttributesTypeFromAttributesProperty (/Users/arnaud/git/carbon-calculator/node_modules/typescript/lib/tsc.js:69288:216)
   at checkJsxAttributes (/Users/arnaud/git/carbon-calculator/node_modules/typescript/lib/tsc.js:69353:12)
   at checkExpressionWorker (/Users/arnaud/git/carbon-calculator/node_modules/typescript/lib/tsc.js:75700:16)
   at checkExpression (/Users/arnaud/git/carbon-calculator/node_modules/typescript/lib/tsc.js:75557:32)
   at checkExpressionWithContextualType (/Users/arnaud/git/carbon-calculator/node_modules/typescript/lib/tsc.js:75203:18)
   at resolveJsxOpeningLikeElement (/Users/arnaud/git/carbon-calculator/node_modules/typescript/lib/tsc.js:72230:51)
   at resolveSignature (/Users/arnaud/git/carbon-calculator/node_modules/typescript/lib/tsc.js:72303:16)

⏯ Playground Link

No response

💻 Code

No response

🙁 Actual behavior

Crash

🙂 Expected behavior

No crash

Additional information about the issue

No response

@Andarist
Copy link
Contributor

Andarist commented Dec 6, 2023

Does it crash on 5.4.0-dev.20231206 too?

@ArnaudBarre
Copy link
Author

It crashes on 20231206 and 20231205, not on 5.3.2. Didn't try other versions

@Andarist
Copy link
Contributor

Andarist commented Dec 6, 2023

removeConstrainedTypeVariables was introduced in #56515 . Could you confirm that 5.4.0-dev.20231130 works OK but 5.4.0-dev.20231201 is broken? Even with that confirmation - it might be hard to fix this without a repro case. If you'd be interested I could try to guide you on how to at least narrow it down to the file in which the problem occurs. With that information, you'd have an easier time dissecting this to a minimal repro case.

@ArnaudBarre
Copy link
Author

ArnaudBarre commented Dec 7, 2023

Ok so yes it crashes starting on 20231201.
I ran the debugger and found the file, and after few try and errors I think this is this combination:

// .d.ts
declare global {
  interface String {
    upperFirst<T extends string>(this: T): Capitalize<T>;
  }
}

// display.ts
const displayEnum = (value: string) => value.toLowerCase().upperFirst();

// Component.tsx
<>{displayEnum("VALUE")}</> 

@jakebailey
Copy link
Member

It's in the template, but you can also use https://www.npmjs.com/package/every-ts to narrow it down further.

I can't get your case to crash in the test suite, unfortunately.

@ArnaudBarre
Copy link
Author

Ok this is the missing piece, the span before is strangely required:
Here is my mininal repro, I don't think my TS config should have an impact on the crash

declare global {
  interface String {
    upperFirst<T extends string>(this: T): Capitalize<T>;
  }
}

const displayEnum = (value: string) => value.toLowerCase().upperFirst();

console.log(
  <div>
    <span>Scope:</span> {displayEnum("VALUE")}
  </div>,
);

export {};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
4 participants