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

typeof with extended generic class #18465

Closed
rzcoder opened this issue Sep 14, 2017 · 5 comments
Closed

typeof with extended generic class #18465

rzcoder opened this issue Sep 14, 2017 · 5 comments
Labels
Duplicate An existing issue was already created

Comments

@rzcoder
Copy link

rzcoder commented Sep 14, 2017

TypeScript Version: 2.4.0+

Code

interface AP {
    id: string;
}

class A<T extends AP = AP> {
    foo(a: T) { }
}

interface BP extends AP {
    n: number;
}

class B<T extends BP = BP> extends A<T> {
}

let y: typeof A;
y = B; // <<<

Expected behavior:
No errors.

Actual behavior:
Error in ts 2.4+ (in 2.3.4 no errors)

Type 'typeof B' is not assignable to type 'typeof A'.
  Type 'B<BP>' is not assignable to type 'A<T>'.
    Types of property 'foo' are incompatible.
      Type '(a: BP) => void' is not assignable to type '(a: T) => void'.
        Types of parameters 'a' and 'a' are incompatible.
          Type 'T' is not assignable to type 'BP'.
            Type 'AP' is not assignable to type 'BP'.
              Property 'n' is missing in type 'AP'.
@mhegazy
Copy link
Contributor

mhegazy commented Sep 14, 2017

looks like the same issue as #18387. please see #18387 (comment)

@mhegazy mhegazy added the Duplicate An existing issue was already created label Sep 14, 2017
@rzcoder
Copy link
Author

rzcoder commented Sep 15, 2017

@mhegazy so, you mean this behaviour is correct?

@mhegazy
Copy link
Contributor

mhegazy commented Sep 15, 2017

@mhegazy so, you mean this behavior is correct?

yes. it is unsafe to substitute a generic constructor with one that is not generic in the general case. you can either change your base class, to be non-generic, or use --noStrictGenerics to suppress the error.

@rzcoder
Copy link
Author

rzcoder commented Sep 19, 2017

So, in this case you just can't extend React component in that simple way. Pretty common scenario but failed in ts, ok :(

@mhegazy
Copy link
Contributor

mhegazy commented Oct 3, 2017

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@mhegazy mhegazy closed this as completed Oct 3, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants