question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Abstract class type argument inference

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:6
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
tinganhocommented, Dec 22, 2016

@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.

0reactions
infengcommented, Jan 11, 2017

I hope it apply to normal class also. see https://github.com/ant-design/ant-design/issues/4324

Read more comments on GitHub >

github_iconTop Results From Across the Web

Infer arguments for abstract class in typescript - Stack Overflow
It is possible to infer parameters of abstract class. You just need to add abstract keyword before new . See example:
Read more >
Type inference of class type parameter in abstract method-kotlin
How to create a class with a method that returns a subtype with a type parameter in Kotlin? ... Can you inherit from...
Read more >
Chapter 3. Type system - Ceylon
Each class declaration defines a type. However, not all types are classes. It is often advantageous to write generic code that abstracts the...
Read more >
Generics: in, out, where | Kotlin Documentation
The set of all possible types that can be substituted for a given type parameter may be restricted by generic constraints. Upper bounds....
Read more >
Documentation - Classes - TypeScript
Constructors can't have type parameters - these belong on the outer class declaration, ... TypeScript has some special inference rules for accessors:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found