-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
stories: fix type loader signature and safety #104307
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
Conversation
| declare module '!!type-loader!*' { | ||
| const TypeLoaderResult: { | ||
| props: Record<string, TypeLoader.ComponentDocWithFilename>; | ||
| exports: Record<string, {name: string; typeOnly: boolean}[]>; | ||
| }; | ||
| const TypeLoaderResult: | ||
| | { | ||
| props: Record<string, TypeLoader.ComponentDocWithFilename>; | ||
| exports: Record<string, {name: string; typeOnly: boolean}[]>; | ||
| } | ||
| // If the type loader is not enabled, the return value is an empty module | ||
| | undefined; | ||
|
|
||
| export default TypeLoaderResult; | ||
| } |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
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 is wrong
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 thought this was legit? The noopTypeLoader would bypass the check here and story.exports.documentation.props would be undefined. The typecasts are obscuring the runtime error.
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 noop loader returns an empty record, so you get Object.entries({}). The type is wonky because both are records, one just never has values. I used undefined because it is more restrictive as a proxy, so it forces you to handle the missing key, but it's an excessive check
natemoo-re
left a comment
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.
Looks good! I think the Seer bug might be legit though?
| declare module '!!type-loader!*' { | ||
| const TypeLoaderResult: { | ||
| props: Record<string, TypeLoader.ComponentDocWithFilename>; | ||
| exports: Record<string, {name: string; typeOnly: boolean}[]>; | ||
| }; | ||
| const TypeLoaderResult: | ||
| | { | ||
| props: Record<string, TypeLoader.ComponentDocWithFilename>; | ||
| exports: Record<string, {name: string; typeOnly: boolean}[]>; | ||
| } | ||
| // If the type loader is not enabled, the return value is an empty module | ||
| | undefined; | ||
|
|
||
| export default TypeLoaderResult; | ||
| } |
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 thought this was legit? The noopTypeLoader would bypass the check here and story.exports.documentation.props would be undefined. The typecasts are obscuring the runtime error.
| declare module '!!type-loader!*' { | ||
| const TypeLoaderResult: { | ||
| props: Record<string, TypeLoader.ComponentDocWithFilename>; | ||
| exports: Record<string, {name: string; typeOnly: boolean}[]>; | ||
| }; | ||
| const TypeLoaderResult: | ||
| | { | ||
| props: Record<string, TypeLoader.ComponentDocWithFilename>; | ||
| exports: Record<string, {name: string; typeOnly: boolean}[]>; | ||
| } | ||
| // If the type loader is not enabled, the return value is an empty module | ||
| | Record<string, undefined>; | ||
|
|
||
| export default TypeLoaderResult; | ||
| } |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
Fixes the type loader signature and uses optional chaining to avoid attempting to access documentation values when the type loader is not enabled.
Fixes the type loader signature and uses optional chaining to avoid attempting to access documentation values when the type loader is not enabled.