Skip to content

Regression: Unrelated line causes complex type check error to disappear #29393

Closed
@phiresky

Description

@phiresky

TypeScript Version: No issue in 3.0.3, broken in both 3.2.2 and 3.3.0-dev.20190112 (using tsconfig from tsc --init)

Search Terms: unrelated, nondeterministic, mapped type, generic

Code

I'm sorry, I couldn't manage to reduce this further since it disappears when the code is too simple (probably some checking depth limitation?)

// when I replace this import by just inlining the corresponding types,
// the error disappears
import { TypeOf, Type } from "io-ts";

type ToB<S extends any> = { [k in keyof S]: TypeOf<S[k]> };
type ToA<S> = { [k in keyof S]: Type<S[k]> };

type NeededInfo<MyNamespaceSchema = {}> = {
  ASchema: ToA<MyNamespaceSchema>;
};

export const ASchema = {
  initialize: null as any
};

export type MyInfo = NeededInfo<ToB<typeof ASchema>>;

const tmp1: MyInfo = null!;
function tmp2<N extends NeededInfo>(n: N) {}
// tmp2(tmp1); // uncommenting this line removes a type error from a completely unrelated line ??

class Server<X extends NeededInfo> {}
export class MyServer extends Server<MyInfo> {} // not assignable error at `MyInfo`

Expected behavior: No type error regardless of whether the line //tmp2(tmp1) is commented or not.

Actual behavior:

When that line is commented out, I get a type error in the export class line, which is completely unrelated:

[ts]
Type 'NeededInfo<ToB<{ initialize: any; }>>' does not satisfy the constraint 'NeededInfo<{}>'.
  Types of property 'ASchema' are incompatible.
    Type 'ToA<ToB<{ initialize: any; }>>' is not assignable to type 'ToA<{}>'.
      Type '{}' is not assignable to type 'ToB<{ initialize: any; }>'. [2344]

Playground Link: Impossible because it stops happening when Type and TypeOf are inlined.

I know the above code looks dumb, but trust me this is causing weird breakage in a large code base.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: Error MessagesThe issue relates to error messaging

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions