Skip to content

Generic wrapper interface no longer assignable  #31804

Closed
@ChiriVulpes

Description

@ChiriVulpes

TypeScript Version: 3.6.0-dev.20190606

Search Terms:
I didn't know how to search for this issue since it's a bit complex

Code

type AnyFunction = (...args: any[]) => any;
type Params<T> = Parameters<Extract<T, AnyFunction>>;

interface Wrapper<T> {
	call<K extends keyof T>(event: K, ...args: Params<T[K]>): void;
}

interface AWrapped {
	foo(): void;
}

class A {
	foo: Wrapper<AWrapped>;
}

interface BWrapped extends AWrapped {
	bar(): void;
}

class B extends A {
	foo: Wrapper<BWrapped>;
}

Expected behavior:
No errors, as it worked in pre 3.5.0

Actual behavior:

Property 'foo' in type 'B' is not assignable to the same property in base type 'A'.
Type 'Wrapper' is not assignable to type 'Wrapper'.
Property 'bar' is missing in type 'AWrapped' but required in type 'BWrapped'

Why? What was this used for?
Our project uses a setup like this for strongly typed events; we define the events in interfaces, and then classes that emit the events store the generic event emitter instances on them. (The actual implementation is a lot more complex, this is a stripped down version)

Previously, it worked to simply override the property's type, but now that doesn't work anymore, and I can't find a workaround. I think this is might prevent our team from updating because of how much this breaks, at least for a time... The amount that has to be rewritten to undo the dependency on this functionality is not negligible.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: Conditional TypesThe issue relates to conditional typesFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions