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

add exactOptionalPropertyTypes support to html attributes #3868

Merged
merged 2 commits into from
Feb 6, 2023

Conversation

deadem
Copy link
Contributor

@deadem deadem commented Jan 23, 2023

With exactOptionalPropertyTypes option enabled in tsconfig.json, assign undefined value to html attributes shouldn't generate an error.

const link: string | undefined
...
<a href={link}>Conditional link</a>

This code generates an error but should not.

React types declaration (for reference only): https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react/index.d.ts#L1917

Preact playground

React playground

This PR continues #3711

@coveralls
Copy link

coveralls commented Jan 23, 2023

Coverage Status

Coverage: 99.543%. Remained the same when pulling 1581fe0 on deadem:exactOptionalPropertyTypes into 8a30bcc on preactjs:master.

@andrewiggins
Copy link
Member

To verify my understanding, with this new option turned on, TypeScript no longer "auto adds" undefined to the type of a property marked as optional using ?. Is that correct?

And this PR just adds undefined to all DOM properties so that we can pass undefined to them when this new option is turned on?

@deadem
Copy link
Contributor Author

deadem commented Jan 24, 2023

To verify my understanding, with this new option turned on, TypeScript no longer "auto adds" undefined to the type of a property marked as optional using ?. Is that correct?

Yes.

And this PR just adds undefined to all DOM properties so that we can pass undefined to them when this new option is turned on?

Yes.

@andrewiggins andrewiggins force-pushed the exactOptionalPropertyTypes branch from d718f00 to 1581fe0 Compare February 6, 2023 19:43
@andrewiggins andrewiggins merged commit b7d9e61 into preactjs:master Feb 6, 2023
@deadem deadem deleted the exactOptionalPropertyTypes branch March 25, 2023 08:57
JoviDeCroock added a commit that referenced this pull request Jan 12, 2024
JoviDeCroock added a commit that referenced this pull request Jan 12, 2024
* backport #3871

* port test from #3884 functionality seems to work in v11

* backport #3880

* backport #3875

* backport #3862

* add todo for #3801

* backport #3868

* backport #3867

* backport #3863

* add todo for #3856

* backport #3844

* backport #3816

* backport #3888

* backport #3889
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.

4 participants