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

Deriving from object and intersection types problem #13732

Closed
tamayika opened this issue Jan 28, 2017 · 2 comments
Closed

Deriving from object and intersection types problem #13732

tamayika opened this issue Jan 28, 2017 · 2 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@tamayika
Copy link

TypeScript Version: nightly (2.2.0-dev.20170128)

Code

interface Person{
  name: string;
}

interface A<T> {

}

type _A<T> = A<T> & T;

interface B<T> extends _A<T> { }

type TypedPerson = B<Person>;

Expected behavior:
no error
Actual behavior:
line interface B<T> extends _A<T> { } is error // TS2312: An interface may only extend a class or another interface.

Now, we can deriving from object and intersection types by #13604.
But this is only for _A<T> is statically composed of object or intersection types.
I think we can solve this problem if we can delay type evaluation until actual type resolution at the line type TypedPerson = B<Person>;
or, we need generics type restriction like below?

interface B<T is interface> extends _A<T> { }
@mhegazy
Copy link
Contributor

mhegazy commented Jan 30, 2017

the T is unknown. it would have been fine to extend from _A<{}>, but not from T. The reason is the compiler does not know what T is at the declaration site, and thus does not know how to check the extends relationship in the interface declaration.

consider using intersection types, as:

type B<T> = _A<T> & { <other declarations> };

@mhegazy mhegazy added the Working as Intended The behavior described is the intended behavior; this is not a bug label Jan 30, 2017
@tamayika
Copy link
Author

OK, thanks!!

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

2 participants