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

Never type creates a typescript issue #1186

Open
yannbriancon opened this issue Jun 12, 2023 · 0 comments
Open

Never type creates a typescript issue #1186

yannbriancon opened this issue Jun 12, 2023 · 0 comments

Comments

@yannbriancon
Copy link

[BUG]

Description

Using never with typescript ends up throwing an error:

Type 'Struct<never, null>' is not assignable to type 'Struct<any, any>'.
  Types of property 'refiner' are incompatible.
    Type '(value: never, context: Context) => Iterable<Failure>' is not assignable to type '(value: any, context: Context) => Iterable<Failure>'.
      Types of parameters 'value' and 'value' are incompatible.
        Type 'any' is not assignable to type 'never'.ts(2322)

Expected Behaviour

No error and a type generated like this:

const User = type({
  name: string(),
  age: never()
});

/*
 * Expected type is:
 * type User = {
 *     name: string,
  *    age: never
  * }

Actual Behaviour

Error breaks the code
image

Reproduction

https://codesandbox.io/s/superstruct-never-typescript-bug-r6nnk4?file=/src/index.ts

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

No branches or pull requests

1 participant