Skip to content

add exactOptionalPropertyTypes support to html attributes#3868

Merged
andrewiggins merged 2 commits into
preactjs:masterfrom
deadem:exactOptionalPropertyTypes
Feb 6, 2023
Merged

add exactOptionalPropertyTypes support to html attributes#3868
andrewiggins merged 2 commits into
preactjs:masterfrom
deadem:exactOptionalPropertyTypes

Conversation

@deadem

@deadem deadem commented Jan 23, 2023

Copy link
Copy Markdown
Contributor

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

coveralls commented Jan 23, 2023

Copy link
Copy Markdown

Coverage Status

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

@andrewiggins

Copy link
Copy Markdown
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

deadem commented Jan 24, 2023

Copy link
Copy Markdown
Contributor Author

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