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

Abstract class type argument inference #13087

Open
tinganho opened this issue Dec 21, 2016 · 5 comments
Open

Abstract class type argument inference #13087

tinganho opened this issue Dec 21, 2016 · 5 comments
Labels
Committed The team has roadmapped this issue Domain: JavaScript The issue relates to JavaScript specifically Suggestion An idea for TypeScript

Comments

@tinganho
Copy link
Contributor

tinganho commented Dec 21, 2016

It would be good if TypeScript can infer the type of an extended class of an generic abstract class:

abstract class A<T> {
    abstract a: T;
    get(): T {
        return '' as any;
    }
}

class B extends A {
    a: 'helloworld';
}

const b = new B():
b.get(); // string

In a similar fashion, it does inference elsewhere.

@aluanhaddad
Copy link
Contributor

This is a really interesting idea. Seems like it would improve life for React users for sure.
Is there any particular reason it would be limited to abstract classes? It seems applicable to interfaces as well as concrete classes.

@RyanCavanaugh RyanCavanaugh added In Discussion Not yet reached consensus Suggestion An idea for TypeScript labels Dec 21, 2016
@tinganho
Copy link
Contributor Author

@aluanhaddad I suggested it applied to abstract, mostly because abstract implies there will be at least another declaration. But after thinking about it, I cannot see why it's not applicable to normal classes as well.

@RyanCavanaugh RyanCavanaugh added Committed The team has roadmapped this issue Salsa and removed In Discussion Not yet reached consensus labels Jan 10, 2017
@RyanCavanaugh
Copy link
Member

See notes at #13368

@tinganho
Copy link
Contributor Author

I hope this covers statics as well, example taken from #10603:

abstract class BaseClass<T> {
    abstract static defaultValue: T;
    // ...
}

class ClassA extends BaseClass {
    static defaultValue = {
         name: 1;
    }
}

@infeng
Copy link

infeng commented Jan 11, 2017

I hope it apply to normal class also. see ant-design/ant-design#4324

@weswigham weswigham added Domain: JavaScript The issue relates to JavaScript specifically and removed Salsa labels Nov 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Committed The team has roadmapped this issue Domain: JavaScript The issue relates to JavaScript specifically Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

5 participants