-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Partial<T> types not working as expected, when extending another interface #21196
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
Comments
So, this is one of many duplicates of #13442, and I imagine that this will be closed. Someone may break out an example like: interface TractorTrailer extends Vehicle {
wheels: 18;
cargo: string;
}
const theBandit = new Driver<TractorTrailer>();
theBandit.car.wheels // 4 at runtime, 18 at compile time... oops But while we're here, could someone explain why this doesn't work? function explainPlease<T extends Vehicle>() {
const err1: Partial<T> = null! as { wheels: T['wheels'] }; // error
const err2: Partial<T> = { wheels: void 0 }; // error
} If I inspect |
I can see that some examples seems completely safe, look at this and please tell me if I'm wrong: interface Entity {
id: string;
}
function aFunction<TItem extends Entity>(): void {
const partialItem: Partial<TItem> = { id: '0' };
// Type { id: "0"; } is not assignable to type Partial<TItem>
}
function anotherFunction<TItem extends Entity>(item: TItem): void {
const partialItem: Partial<TItem> = item; // this works correctly
item.id = "new";
partialItem.id = "new"; // this works correctly
} I know that TItem extends Entity (pseudo code) |
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.7.0-insiders.20180108
Code
The text was updated successfully, but these errors were encountered: