-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Partials with extends works incorrectly with object literals #17491
Comments
This does what you want function foo<Super>(superObj: Partial<Super>, partObj: Partial<Super & {}>) { }
foo({ foo: 1, bar: '2' }, { foo: 1, bar: '' }); // it's ok
foo({ foo: 1, bar: '2' }, { foo: 1 }); // it's ok
foo({ foo: 1, bar: '2' }, { foo: 1, Bar: '' }); // errors
foo({ foo: 1, bar: '2' }, { foo: 1, bar: '', baz: '' }); // errors See also #14829 |
Also doesn't work for Records function foo<Super, Part extends Partial<Record<keyof Super, any>>>(superObj: Super, partObj: Part) {}
foo({foo: 'foo', bar: 'bar'}, {foo: 1, bar: 1, sdf: 1}); // no error but should be |
@RyanCavanaugh How can I return partObj type from function? function foo<Super>(superObj: Partial<Super>, partObj: Partial<Super & {}>) { return partObj }
foo({ foo: 1, bar: '2' }, { foo: 1 }).bar // no errored |
It would be helpful to understand what you want the semantics of the function to be. |
@RyanCavanaugh interface Class<T> {
new (): T;
}
class Foo {
foo: number;
bar: string;
}
function validate<Super, Args>(Cls: Partial<Class<Super>>, partObj: Partial<Super & {}>, args: Args) {
return {...partObj, __class: Cls, __args: args}
}
function fetchGraphQL<T>(scheme: T): Promise<T> {}
fetchGraphQL(validate(Foo, { foo: 1 }, {arg: 1})).then(obj => obj.foo); |
This case works, but without fields autocomplete function validate<Super extends Part, Part, Args>(Cls: Class<Super>, partObj: Part, args: Args): Part {} |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
TypeScript Version: 2.5.0 nightly
Code
The text was updated successfully, but these errors were encountered: