-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Maintenance: Fix @ts-expect-error
strict types
#20981
Conversation
const exportName = propKey(p); | ||
if (exportName) { | ||
let exportVal = p.value; | ||
let exportVal = p.value as t.Expression; |
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.
Why do we need all these extra type annotations? Is it causing a problem without?
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.
Yes, #20877
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.
@valentinpalkovic & I are affected, can't do changes without disabling strict mode and do few changes
@@ -109,7 +109,7 @@ export const getStorySortParameter = (previewCode: string) => { | |||
|
|||
if (t.isFunctionExpression(storySort)) { | |||
const { code: sortCode } = generate.default(storySort, {}); | |||
const functionName = storySort.id.name; | |||
const functionName = storySort.id?.name; |
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 wonder if we should add a TODO comment here to remind to take a look at this code.
if storySort.id can be undefined, it means that the code right after will generate invalid code, e.g.:
return undefined(a, b)
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.
@sheriffMoose @ndelangen seems like this PR got merged but this was taken into account. Do you think this might bite us back if we don't at least add a TODO there?
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.
If you feel like there should be a comment, and you have an idea what that comment should look like, sure.
I don't have a recollection of this context anymore.
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 (now merged) code looks like this:
if (t.isFunctionExpression(storySort)) {
const { code: sortCode } = generate.default(storySort, {});
const functionName = storySort.id?.name;
// Wrap the function within an arrow function, call it, and return
const wrapper = `(a, b) => {
${sortCode};
return ${functionName}(a, b)
}`;
// eslint-disable-next-line no-eval
return (0, eval)(wrapper);
}
so if storySort.id
is optional, then storySort.id?.name
could be undefined, right? meaning that functionName
becomes undefined.
later on, return ${functionName}(a, b)
will get executed. But then, if functionName
is undefined, the evaluated code will be undefined(a,b)
, which will crash.
@ts-expect-error
strict types@ts-expect-error
strict types
@sheriffMoose Can you merge the latest |
Closes #20877
What I did
How to test