Skip to content

Support exactOptionalPropertyTypes (tsc) #391

@connorjs

Description

@connorjs

Is your feature request related to a problem? Please describe.

I have a TypeScript project with exactOptionalPropertyTypes: true. When I use graphql-yoga, I get a tsc error because Yoga’s type has url?: string | undefined while NodeRequest (this package) has url?: string.

Describe the solution you'd like

I would like this package to update its optional typing to include | undefined.

Describe alternatives you've considered

  1. Turn off exactOptionalPropertyTypes
  2. Use @ts-ignore
  3. Open the opposite request with graphql yoga (remove the | undefined)

Additional context

I really like the idea of exactOptionalPropertyTypes, but I have found it hard to adopt given cases such as this one. When I write “library” code with options objects, I usually do foo?: Foo | undefined for compatibility, and reserve the specific ? or | undefined for non-options function inputs (for example: path?: string vs. path: string | undefined) or for my own application code to refactor.

Open to general thoughts on exactOptionalPropertyTypes, including if the existing types without | undefined are better.

If accepted, it seems like an easy PR to do myself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions