Skip to content

Type checking regression in mithril #28388

Closed
@ghost

Description

TypeScript Version: 3.2.0-dev.20181106

Code

interface Lifecycle<Attrs, State> {
	oninit?(vnode: Vnode<Attrs, State>): number;
	[_: number]: any;
}

interface Vnode<Attrs, State extends Lifecycle<Attrs, State> = Lifecycle<Attrs, State>> {
	tag: Component<Attrs, State>;
}

interface Component<Attrs, State> {
	view(this: State, vnode: Vnode<Attrs, State>): number;
}

interface ClassComponent<A> extends Lifecycle<A, ClassComponent<A>> {
	oninit?(vnode: Vnode<A, this>): number;
	view(vnode: Vnode<A, this>): number;
}

interface Attrs { id: number }
class C implements ClassComponent<Attrs> {
	view(v: Vnode<Attrs>) { return 0; }
}

const test8: ClassComponent<any> = new C();

Expected behavior:

No error, as in typescript@3.1.

Actual behavior:

src/a.ts:24:7 - error TS2322: Type 'C' is not assignable to type 'ClassComponent<any>'.
  Types of property 'view' are incompatible.
    Type '(v: Vnode<Attrs, Lifecycle<Attrs, Lifecycle<Attrs, State>>>) => number' is not assignable to type '(vnode: Vnode<any, ClassComponent<any>>) => number'.
      Types of parameters 'v' and 'vnode' are incompatible.
        Type 'Vnode<any, ClassComponent<any>>' is not assignable to type 'Vnode<Attrs, Lifecycle<Attrs, Lifecycle<Attrs, State>>>'.
          Type 'ClassComponent<any>' is not assignable to type 'Lifecycle<Attrs, Lifecycle<Attrs, State>>'.
            Types of property 'oninit' are incompatible.
              Type '((vnode: Vnode<any, ClassComponent<any>>) => number) | undefined' is not assignable to type '((vnode: Vnode<Attrs, Lifecycle<Attrs, State>>) => number) | undefined'.
                Type '(vnode: Vnode<any, ClassComponent<any>>) => number' is not assignable to type '(vnode: Vnode<Attrs, Lifecycle<Attrs, State>>) => number'.
                  Types of parameters 'vnode' and 'vnode' are incompatible.
                    Type 'Vnode<Attrs, Lifecycle<Attrs, State>>' is not assignable to type 'Vnode<any, ClassComponent<any>>'.
                      Type 'Lifecycle<Attrs, State>' is not assignable to type 'ClassComponent<any>'.
                        Property 'view' is missing in type 'Lifecycle<Attrs, State>'.

24 const test8: ClassComponent<any> = new C();
         ~~~~~


Found 1 error.

Found in mithril on DefinitelyTyped.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: This-TypingThe issue relates to providing types to this

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions