microsoft / microsoft/TypeScript
[P in keyof T]: T[P] not accepting inferred base type via extends
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.8.3
Search Terms:
[P in keyof T]?: T[P]typescript generic extends in keyoftypescript generic extends T[P]typescript mongo collection generic
Code
interface IModel {
id: string;
}
type Query<T> = {
[P in keyof T]?: T[P]
}
export class Base<T extends IModel> {
public find(query: Query<T>): void {
// Forward the query to database
console.log(query);
}
public findOneById(id: string): void {
this.find({ id });
}
}
Expected behavior:
It's expected to allow to execute the find with the properties defined on IModel as base of any other model;
Actual behavior:
It shows an error:
Argument of type '{ id: string; }' is not assignable to parameter of type 'Query<T>'.ts(2345)
Playground Link:
Related Issues:
Didn't find any related issue
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 by reproducing the TypeScript 3.8.3 example from the issue and its Playground link, then read the comment thread for the current consensus. No source file or test is named; the work is complete when the generic find call using the IModel property is consistently accepted or the expected behavior is clearly resolved.
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