You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importtsfrom'typescript';constsourceCode='export const id = <T,>(id: T): T => id';constsourceFile=ts.createSourceFile('index.tsx',sourceCode,ts.ScriptTarget.Latest,undefined,ts.ScriptKind.TSX);constprinter=ts.createPrinter();constprinted=printer.printFile(sourceFile);console.log('Original:');console.log(sourceCode);// 'export const id = <T,>(id: T): T => id;'console.log('Printed:');console.log(printed);// 'export const id = <T>(id: T): T => id;'
Uh oh!
There was an error while loading. Please reload this page.
🔎 Search Terms
tsx printer printing syntax error generic type parameter
🕗 Version & Regression Information
TypeScript/src/compiler/emitter.ts
Lines 4507 to 4512 in 4b12d82
⏯ Playground Link
https://github.com/maxpatiiuk/typescript-printer-tsx-syntax-error
💻 Code
🙁 Actual behavior
The printer removes trailing comma from the generic type parameters list.
That trailing comma is crucial to correctly parse the
.tsx
files. See how without it TypeScript (and ESBuilt and others) are reporting a syntax error: https://www.typescriptlang.org/play/?target=99#code/KYDwDg9gTgLgBAYwgOwM7wEbAGbWABSgEtl4BeOAHgBUAaAPgAoiATALjmoEoPq4z6cVgChQkWIhTo4AQ2wxgUQiXJVqTVrx6d+g1kA🙂 Expected behavior
When generic type parameters are used in
.tsx
files, the list must end with,
to disambiguate the syntax from jsx opening tagAdditional information about the issue
See also #15713
The text was updated successfully, but these errors were encountered: