Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add more precise typing for autocomplete HTML attribute #1467
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
Add more precise typing for autocomplete HTML attribute #1467
Changes from all commits
ef9854e
b62fee2
8179c44
88318d6
6d6f63e
5bc8f65
b3466ed
5453d21
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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 problematic as it allows space:
section-foo bar baz
is allowed asAutoFillSection
.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.
Oh ok, There was a test for
section-wrong off
, and even justsection-foo bar baz
is disallowed, but indeed something likesection-foo bar baz username
currently passes.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.
Honestly it doesn't seem trivial, I don't think I'm fluent enough in typescript to do this (or if it's possible at all).
I will add tests that show the expected and unexpected cases anyway.
I'll continue looking into it but I would argue that the current type (before this PR) allows much more invalid values, so maybe we could iterate on it? Or do you feel like it would be a blocker?
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 can see how to do it with a generic, but not inside a template literal type:
playground
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, pretty sure it's not currently possible. Anyway as I said, still much less false positives than before. :)
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.
@sandersn This one is the main reason I'm not approving, what do you think?
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 think some overgeneration is OK as long as it's not rejecting values that are legal.
I do wonder about performance though. Let me look again at the generated size of the type.
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.
Note for other readers that it is not a full catch-all, you still need to add valid tokens to your attribute, so for example,
section-foo bar baz username
would pass but notsection-foo bar baz
alone, norsection-wrong off
as shown in the tests.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.
@sandersn: Hi, I've pushed the final version, are you ok with the generated types?
https://github.com/microsoft/TypeScript-DOM-lib-generator/pull/1467/files#diff-d57c51d024219b9f37e6b42df127db25f700acbaade23ce1edcecda2853b995c
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.
Can you add a TODO comment about the over-match of
section-{string}
?