-
-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,8 @@ import { babelParse } from './babelParse'; | |
const logger = console; | ||
|
||
const getValue = (obj: t.ObjectExpression, key: string) => { | ||
let value: t.Expression; | ||
obj.properties.forEach((p: t.ObjectProperty) => { | ||
let value: t.Expression | undefined; | ||
(obj.properties as t.ObjectProperty[]).forEach((p) => { | ||
if (t.isIdentifier(p.key) && p.key.name === key) { | ||
value = p.value as t.Expression; | ||
} | ||
|
@@ -20,12 +20,12 @@ const getValue = (obj: t.ObjectExpression, key: string) => { | |
|
||
const parseValue = (expr: t.Expression): any => { | ||
if (t.isArrayExpression(expr)) { | ||
return expr.elements.map((o: t.Expression) => { | ||
return (expr.elements as t.Expression[]).map((o) => { | ||
return parseValue(o); | ||
}); | ||
} | ||
if (t.isObjectExpression(expr)) { | ||
return expr.properties.reduce((acc, p: t.ObjectProperty) => { | ||
return (expr.properties as t.ObjectProperty[]).reduce((acc, p) => { | ||
if (t.isIdentifier(p.key)) { | ||
acc[p.key.name] = parseValue(p.value as t.Expression); | ||
} | ||
|
@@ -60,7 +60,7 @@ const unsupported = (unexpectedVar: string, isError: boolean) => { | |
}; | ||
|
||
export const getStorySortParameter = (previewCode: string) => { | ||
let storySort: t.Expression; | ||
let storySort: t.Expression | undefined; | ||
const ast = babelParse(previewCode); | ||
traverse.default(ast, { | ||
ExportNamedDeclaration: { | ||
|
@@ -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 commentThe 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.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 later on, |
||
// Wrap the function within an arrow function, call it, and return | ||
const wrapper = `(a, b) => { | ||
${sortCode}; | ||
|
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