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

Supporting exactOptionalPropertyTypes #2111

Merged
merged 4 commits into from
Apr 19, 2023
Merged

Conversation

seivan
Copy link
Contributor

@seivan seivan commented Nov 15, 2022

YogaServerOptions has a bunch of keys that are defined as optional, but haven't declared their value as such, even though this happens implicitly since no key means no value which translates to undefined:

    key?: string;

To support exactOptionalPropertyTypes and retains its API it would have to be defined as:

    key?: string | undefined;

While you could say the key isn't optional (removing ?), which then requires an explicit undefined value:

    key: string | undefined;

That would require an explicit undefined being passed and would break builds and alter its API.

`signal` key has defined its key as optional, not necessarily the value even though this happens implicitly.  No key means no value which translates to `undefined`:

```ts
    signal?: AbortSignal | null;
```

To support `exactOptionalPropertyTypes` it would have to be defined as: 
```ts
    signal?: AbortSignal | null | undefined;
```

While you could say the key isn't optional (removing `?`), which then requires an explicit `undefined` value: 
```ts
    signal: AbortSignal | null | undefined;
```

That would require an explicit undefined being passed. 

Given this key is part of TS definitions and module augmentation is overkill, just "oring" from undefined to an expected value (in this case `null`) solves the problem.
@changeset-bot
Copy link

changeset-bot bot commented Nov 15, 2022

⚠️ No Changeset found

Latest commit: 8774ceb

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Collaborator

@saihaj saihaj left a comment

Choose a reason for hiding this comment

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

I guess we can use Maybe type in this case

@theguild-bot theguild-bot mentioned this pull request Nov 23, 2022
@ardatan ardatan merged commit 89d7c61 into dotansimha:main Apr 19, 2023
4 of 5 checks passed
@ardatan
Copy link
Collaborator

ardatan commented Apr 19, 2023

Thanks for the PR!

@theguild-bot theguild-bot mentioned this pull request Apr 20, 2023
@seivan seivan deleted the patch-1 branch September 14, 2023 06:01
This was referenced May 7, 2024
This was referenced May 23, 2024
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.

None yet

3 participants