Skip to content

Conversation

@ZettZet
Copy link

@ZettZet ZettZet commented Nov 14, 2023

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.

Copy link
Owner

@kimamula kimamula left a 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?

"moduleResolution": "node",
"noEmitOnError": true,
"suppressImplicitAnyIndexErrors": true,
"noUncheckedIndexedAccess": false,
Copy link
Owner

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.

strict: true,
noEmitOnError: true,
suppressImplicitAnyIndexErrors: true,
noUncheckedIndexedAccess: false,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also seems unnecessary.

suppressImplicitAnyIndexErrors: true,
noUncheckedIndexedAccess: false,
esModuleInterop: true,
moduleResolution: getDefaultModuleResolution(),
Copy link
Owner

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.

Comment on lines +4 to +36
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");
})();
Copy link
Owner

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:

Suggested change
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?

"noFallthroughCasesInSwitch": true,
"esModuleInterop": true
"esModuleInterop": true,
"noUncheckedIndexedAccess": false
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also seems unnecessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants