microsoft / microsoft/TypeScript
Infer type arguments from 'super()' calls
Open
Nobody has claimed this yet.
In Discussion
Suggestion
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
interface Component {
whatever: number;
}
type ComponentConstructor = new <T = {}>(extra: T) => Component & T;
declare const Component: ComponentConstructor;
class ReallyOldComponent extends Component {
constructor() {
super({ name: "Methuselah", age: 969 });
}
blah() {
this.whatever;
this.age;
}
}
Ideally this would produce no errors; in fact, ideally I wouldn't need to specify any type parameter defaults on ComponentConstructor's signature. However, instead, T is inferred as {} and in blah it is an error to access this.age.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the TypeScript compiler's handling of generic class construction and super() calls, using the provided reproduction as the baseline. The work is done when the example produces no errors, the inferred type includes age on this, and no default type parameter is required.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100