Skip to content

fix: crashes when JSX.IntrinsicClassAttributes is an alias type close GH-50254 #50257

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

Merged
merged 1 commit into from
Aug 10, 2022

Conversation

Jack-Works
Copy link
Contributor

Fixes #50254

@weswigham
Copy link
Member

Thanks!

@Jack-Works Jack-Works deleted the fix50254 branch August 11, 2022 02:22
Comment on lines +27616 to +27617
if (typeParams && typeParams.length === 1) {
const inferredArgs = fillMissingTypeArguments([hostClassType], typeParams, getMinTypeArgumentCount(typeParams), isInJSFile(context));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh, since I checked the typeParams length, I should not call fillMissingTypeArguments.

Which is preferred? To limit the generics number of JSX.IntrinsicClassAttributes = 1, or allow any argument count and call fillMissingTypeArguments to fill it?

@weswigham

Copy link
Member

Choose a reason for hiding this comment

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

I usually err on the side of being permissive, since we've never surfaced real errors for these intrinsic types - so allowing too many arguments, but only providing the first and defaulting/constraint'ing the rest. Not much reasoning for either way, though. It's essentially a quiet error case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, they're not intrinsic types, they're installed from npm. That's also true for libes6.d.ts etc, you can use nolib and provide you're own Promise<T> type. Maybe there's more incorrect cast in the checker assuming the shape of the library types and might crash under some edge cases.

Copy link
Member

Choose a reason for hiding this comment

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

Most use the getGlobalType function which issues an error if arity doesn't match what we expect. The JSX types have just always been a bit more lax.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I opened #50271 to clean up the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeScript createTypeReference crashes with TypeError: Cannot read properties of undefined (reading 'get')
3 participants