-
Notifications
You must be signed in to change notification settings - Fork 85
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
Adds Typescript 5+ support #106
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for raising this PR! Can you take a look at my comments?
@@ -4,7 +4,7 @@ | |||
"module": "es2015", | |||
"moduleResolution": "node", | |||
"noEmitOnError": true, | |||
"suppressImplicitAnyIndexErrors": true, | |||
"noUncheckedIndexedAccess": false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't remember why I added suppressImplicitAnyIndexErrors
in the tsconfig.json files in the examples
folder, but it seems ts files compile without this option. Can you just remove the option without adding noUncheckedIndexedAccess
? It seems unnecessary.
export function compile(filePaths: string[], target = ts.ScriptTarget.ES5, writeFileCallback?: ts.WriteFileCallback) { | ||
const program = ts.createProgram(filePaths, { | ||
strict: true, | ||
noEmitOnError: true, | ||
suppressImplicitAnyIndexErrors: true, | ||
noUncheckedIndexedAccess: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also seems unnecessary.
esModuleInterop: true, | ||
moduleResolution: getDefaultModuleResolution(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed? I confirmed npm test
succeeds without this.
type ArrayFactory = ( | ||
elements?: readonly ts.Expression[] | undefined, | ||
multiLine?: boolean | undefined | ||
) => ts.ArrayLiteralExpression; | ||
|
||
const createArrayExpression = ((): ArrayFactory => { | ||
if (ts.factory) { | ||
return ts.factory.createArrayLiteralExpression; | ||
} | ||
|
||
if ("createArrayLiteral" in ts) { | ||
return ts.createArrayLiteral as ArrayFactory; | ||
} | ||
|
||
throw new Error("Cannot choose array literal factory"); | ||
})(); | ||
|
||
type StringFactory = ( | ||
text: string, | ||
isSingleQuote?: boolean | undefined | ||
) => ts.StringLiteral; | ||
|
||
const createStringLiteral = ((): StringFactory => { | ||
if (ts.factory) { | ||
return ts.factory.createStringLiteral; | ||
} | ||
|
||
if ("createLiteral" in ts) { | ||
return ts.createLiteral as StringFactory; | ||
} | ||
|
||
throw new Error("Cannot choose string literal factory"); | ||
})(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following should be much easier:
type ArrayFactory = ( | |
elements?: readonly ts.Expression[] | undefined, | |
multiLine?: boolean | undefined | |
) => ts.ArrayLiteralExpression; | |
const createArrayExpression = ((): ArrayFactory => { | |
if (ts.factory) { | |
return ts.factory.createArrayLiteralExpression; | |
} | |
if ("createArrayLiteral" in ts) { | |
return ts.createArrayLiteral as ArrayFactory; | |
} | |
throw new Error("Cannot choose array literal factory"); | |
})(); | |
type StringFactory = ( | |
text: string, | |
isSingleQuote?: boolean | undefined | |
) => ts.StringLiteral; | |
const createStringLiteral = ((): StringFactory => { | |
if (ts.factory) { | |
return ts.factory.createStringLiteral; | |
} | |
if ("createLiteral" in ts) { | |
return ts.createLiteral as StringFactory; | |
} | |
throw new Error("Cannot choose string literal factory"); | |
})(); | |
declare module "typescript" { | |
const createArrayLiteral: typeof ts.factory.createArrayLiteralExpression; | |
const createLiteral: typeof ts.factory.createStringLiteral; | |
} | |
const createArrayExpression = ts.factory ? ts.factory.createArrayLiteralExpression : ts.createArrayLiteral; | |
const createStringLiteral = ts.factory ? ts.factory.createStringLiteral : ts.createLiteral; |
What do you think?
@@ -6,7 +6,8 @@ | |||
"noEmitOnError": true, | |||
"noImplicitReturns": true, | |||
"noFallthroughCasesInSwitch": true, | |||
"esModuleInterop": true | |||
"esModuleInterop": true, | |||
"noUncheckedIndexedAccess": false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also seems unnecessary.
Many deprecated parts of tsAPI were removed from the ts5 release, so updating to ts5 breaks projects.
Added support to the new API with the help of dynamic checks of what API version is used right now.