ianstormtaylor / superstruct

A simple and composable way to validate data in JavaScript (and TypeScript).

Home Page:https://docs.superstructjs.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Never type creates a typescript issue

yannbriancon opened this issue · comments

[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