Skip to content
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

feat: support type constraints for generic types #257

Merged
merged 2 commits into from
Oct 8, 2024

Conversation

tomivirkki
Copy link
Member

@tomivirkki tomivirkki commented Aug 26, 2024

Description

Support providing type constraints to component generic types.

This feature is required by the upcoming Dashboard component which has a constraint for the item type it is given.

You can test the feature, for example. by adding typeConstraints: ['VirtualListDefaultItem'] to "VirtualList" in the settings.ts file and then running npm run build
The resulting difference in the src/generated/VirtualList.d.ts file:

Screenshot 2024-08-26 at 16 36 37

Type of change

Feature

Comment on lines -228 to +234
? genericTypeNames.map(() => ts.factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword))
? genericTypeNames.map(() => ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword))
Copy link
Member Author

Choose a reason for hiding this comment

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

Also needed to change the generic type of the Event Map passed to createComponent to any since unknown doesn't satisfy the constraint:

Screenshot 2024-08-26 at 16 47 42

@tomivirkki tomivirkki merged commit e12ca66 into main Oct 8, 2024
2 checks passed
@tomivirkki tomivirkki deleted the generator-generic-type-constraint branch October 8, 2024 06:41
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