Closed
Description
TypeScript Version: 2.7.0-dev.201xxxxx
Search Terms:
Code
const property: keyof IArrayItem = "test";
interface IArrayItem {
test: string;
}
function A<T extends IArrayItem = IArrayItem>(array: T[]) {
const t: Partial<T> = { test: "aaa" }; // Error: Type '{ test: "aaa"; }' is not assignable to type 'Partial<T>'.
const t2: Partial<IArrayItem> = { test: "aaa" }; // Works
}
const array: IArrayItem[] = [];
A(array);
Expected behavior:
No type check errors
Actual behavior:
Error: Type '{ test: "aaa"; }' is not assignable to type 'Partial'
Playground Link: playground
Related Issues:
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
Delagen commentedon Apr 28, 2018
See also this discussion DefinitelyTyped/DefinitelyTyped@64104e9
Lowdb test fix (#25204)
jack-williams commentedon Apr 28, 2018
I think this should be an error. There is no guarantee that the object literal is assignable for all possible
Partial<T>
. A caller is free to instantiate the generic inA
to be the following typeT
.ahejlsberg commentedon Apr 28, 2018
This is working as intended and is a duplicate of many existing issues, e.g. #19388, #17071, #13442.