microsoft / microsoft/TypeScript
Mixin classes don't allow constructors of _generic_ 'object' types
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 2.3.4, 2.4.0-dev.20170609
Code:
type Constructor<T> = new (...args: any[]) => T;
const Timestamped = <I extends object, CT extends Constructor<I>>(Base: CT) => {
return class extends Base {
timestamp = new Date();
};
};
Expected behavior:
Should be able to use the generic I as an argument to Constructor.
Actual behavior:
Compiling this yields the following error:
error TS2509: Base constructor return type 'I' is not a class or interface type.
Note:
This is a variation on https://github.com/Microsoft/TypeScript/issues/13805 where the following compiles successfully:
type Constructor<T> = new (...args: any[]) => T;
const Timestamped = <CT extends Constructor<object>>(Base: CT) => {
return class extends Base {
timestamp = new Date();
};
};
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 constructor return types and reproduce the example from the issue using TypeScript 2.3.4 or the referenced development version. Done means the generic I can be used as the Constructor argument without TS2509, while the object variant and existing mixin behavior continue to compile.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100