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

TypeScript 4.7 beta compile errors #647

Closed
joeltg opened this issue May 9, 2022 · 4 comments
Closed

TypeScript 4.7 beta compile errors #647

joeltg opened this issue May 9, 2022 · 4 comments
Labels

Comments

@joeltg
Copy link

joeltg commented May 9, 2022

🐛 Bug report

This is a separate issue from #644, not related to ESM compatibility (as far as I can tell).

Current Behavior

io-ts fails to compile under the new TypeScript 4.7 beta.

Expected behavior

io-ts compiles without emitting any errors.

Reproducible example

package.json:

{
  "name": "example",
  "scripts": {
    "build": "tsc"
  },
  "dependencies": {
    "fp-ts": "^2.12.1",
    "io-ts": "^2.2.16"
  },
  "devDependencies": {
    "typescript": "^4.7.0-beta"
  }
}

tsconfig.json:

{ 
  "compilerOptions": {
    "strict": true
  }
}

index.ts:

import * as t from "io-ts"

const thing = t.type({ foo: t.string })
console.log(thing.is(5))
console.log(thing.is({ foo: "wow" }))
% npm run build

> example@0.0.0 build
> tsc

node_modules/io-ts/lib/index.d.ts:1387:29 - error TS2344: Type 'O' does not satisfy the constraint 'Exact<O, O>'.
  Type 'O' is not assignable to type '{ [K in ({ [K in keyof O]: K; } & { [K in keyof O]: never; } & { [key: string]: never; })[keyof O]]?: undefined; }'.

1387   OO extends Exact<O, OO> = O,
                                 ~

  node_modules/io-ts/lib/index.d.ts:1383:34
    1383 export declare function alias<A, O, P, I>(
                                          ~
    This type parameter probably needs an `extends object` constraint.

node_modules/io-ts/lib/index.d.ts:1388:29 - error TS2344: Type 'P' does not satisfy the constraint 'Exact<P, P>'.
  Type 'P' is not assignable to type '{ [K in ({ [K in keyof P]: K; } & { [K in keyof P]: never; } & { [key: string]: never; })[keyof P]]?: undefined; }'.

1388   PP extends Exact<P, PP> = P,
                                 ~

  node_modules/io-ts/lib/index.d.ts:1383:37
    1383 export declare function alias<A, O, P, I>(
                                             ~
    This type parameter probably needs an `extends object` constraint.

node_modules/io-ts/lib/index.d.ts:1395:29 - error TS2344: Type 'O' does not satisfy the constraint 'Exact<O, O>'.
  Type 'O' is not assignable to type '{ [K in ({ [K in keyof O]: K; } & { [K in keyof O]: never; } & { [key: string]: never; })[keyof O]]?: undefined; }'.

1395   OO extends Exact<O, OO> = O,
                                 ~

  node_modules/io-ts/lib/index.d.ts:1391:34
    1391 export declare function alias<A, O, P, I>(
                                          ~
    This type parameter probably needs an `extends object` constraint.

node_modules/io-ts/lib/index.d.ts:1396:29 - error TS2344: Type 'P' does not satisfy the constraint 'Exact<P, P>'.
  Type 'P' is not assignable to type '{ [K in ({ [K in keyof P]: K; } & { [K in keyof P]: never; } & { [key: string]: never; })[keyof P]]?: undefined; }'.

1396   PP extends Exact<P, PP> = P,
                                 ~

  node_modules/io-ts/lib/index.d.ts:1391:37
    1391 export declare function alias<A, O, P, I>(
                                             ~
    This type parameter probably needs an `extends object` constraint.

node_modules/io-ts/lib/index.d.ts:1403:29 - error TS2344: Type 'O' does not satisfy the constraint 'Exact<O, O>'.
  Type 'O' is not assignable to type '{ [K in ({ [K in keyof O]: K; } & { [K in keyof O]: never; } & { [key: string]: never; })[keyof O]]?: undefined; }'.

1403   OO extends Exact<O, OO> = O,
                                 ~

  node_modules/io-ts/lib/index.d.ts:1399:34
    1399 export declare function alias<A, O, P, I>(
                                          ~
    This type parameter probably needs an `extends object` constraint.

node_modules/io-ts/lib/index.d.ts:1404:29 - error TS2344: Type 'P' does not satisfy the constraint 'Exact<P, P>'.
  Type 'P' is not assignable to type '{ [K in ({ [K in keyof P]: K; } & { [K in keyof P]: never; } & { [key: string]: never; })[keyof P]]?: undefined; }'.

1404   PP extends Exact<P, PP> = P,
                                 ~

  node_modules/io-ts/lib/index.d.ts:1399:37
    1399 export declare function alias<A, O, P, I>(
                                             ~
    This type parameter probably needs an `extends object` constraint.


Found 6 errors in the same file, starting at: node_modules/io-ts/lib/index.d.ts:1387

Suggested solution(s)

The errors show a couple suggestions but I don't understand them very well.

Additional context

Your environment

Which versions of io-ts are affected by this issue? Did this work in previous versions of io-ts?

Software Version(s)
io-ts 2.2.16
fp-ts 2.12.1
TypeScript 4.7.0-beta
@lkj4
Copy link

lkj4 commented Jun 6, 2022

@gcanti do you have time to look into this?

@gcanti
Copy link
Owner

gcanti commented Jun 6, 2022

@joeltg @lkj4 I can't reproduce with typescript@4.7.3

@florianbepunkt
Copy link

There is another 4.7 related error in #644 Not sure if they are related, but with 4.7 came some changes/improvements to the type inference, so there might be a connection.

@vsapronov
Copy link

It works in TypeScript 4.7.4 but it does not work in: 4.8.0-beta, 4.8.1-rc, and 4.8.2. So it's again broken in the latest TypeScript 4.8.

@gcanti gcanti added the bug label Aug 28, 2022
gcanti added a commit that referenced this issue Aug 28, 2022
@gcanti gcanti closed this as completed in 9e8ef0e Aug 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants