microsoft / microsoft/TypeScript
Inferred missing properties use resolved generic types rather than staying generic
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 3.3.0-dev.20181212
Search Terms: declare property generic missing member
Code
class TestClass<T> {
// Inferred:
// otherValue: number;
public constructor(
public readonly value: T,
) { }
}
const foo = new TestClass<number>(1);
foo.otherValue = foo.value;
Expected behavior:
Declare property 'otherValue' should create otherValue: T;
Actual behavior:
...but it actually creates otherValue: number. Whatever generic type from the place you request the missing property be added will be the type of the property.
Related Issues: I found a lot of similar bugs but didn't see any that looked related...
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 provided TypeScript playground reproduction using typescript@next and verify whether the behavior still occurs. Trace how the missing property is inferred from the generic class and instantiated value. Done means the declared property preserves the generic type T rather than resolving to number, with a regression test covering the example.
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
- Mostly clear
- Newbie friendliness
- 35/100