-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
Type Inference Issues #15709
Comments
The excess property checks, which is what reports the other errors in this sample, only works on object literals. the assumption is an object literal with extra properties is just wrong; this is not the case with references, since you might wasn't to use I guess what you are looking for is exact types, where a type is closed and can not have any additional members. |
I guess that makes sense. Before I close this issue, could you tell me if the next example is related? type DeepPartial<T> = {[P in keyof T]?: T[P] | (DeepPartial<T[P]> & object) };
type IName = {
name: string;
}
type IType = {
typeName: IName;
}
type IRoom = {
roomType: IType;
}
type IUser = {
room: IRoom;
}
const p0: Partial<IUser> = { room: 0 }; // BAD - room should be IRoom | undefined
const p1: DeepPartial<IUser> = { room: 0 }; // BAD - room should can't be a number
const p2: DeepPartial<IUser> = { room: {} }; // OK - we have a DeepPartial<IRoom>
const p3: DeepPartial<IUser> = { room: { a: 0 } }; //BAD - `a` doesn't exists in IRoom
const p4: DeepPartial<IUser> = { room: { roomType: 0 } }; // BAD - roomType can't be a number
const p5: DeepPartial<IUser> = { room: { roomType: {} } }; // GOOD - there's a deep partial
const p6: DeepPartial<IUser> = { room: { roomType: { a: 0 } } }; // ? should be bad
const p7: DeepPartial<IUser> = { room: { roomType: { typeName: 0 } } }; // BAD - can't be number
const p8: DeepPartial<IUser> = { room: { roomType: { typeName: {} } } }; // GOOD - DeepPartial
const p9: DeepPartial<IUser> = { room: { roomType: { typeName: { a: 0 } } } }; // ? should be bad
const p10: DeepPartial<IUser> = { room: { roomType: { typeName: { name: 0 } } } }; // BAD - string
const p11: DeepPartial<IUser> = { room: { roomType: { typeName: { name: '0' } } } }; // GOOD The playground is able to detect 6 correct errors, but I think it is missing 2 errors. Namely the ones I commented with I was trying to see if my definition of In |
That is caused by the I think i understand why you added it, but i am afraid it does not do what you intended. you are running into a limitation that any object with only optional property is equivalent to |
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.3.2
Code
Expected behavior:
It should warn about the assignment to
r1
as it does inr3
.Actual behavior:
Typescript does not warn me of a mistake when we declare
r1
. In the declaration ofr3
it even says that{a: number}
cannot be assigned toIType | (DeepPartial<IType> & object)
. Why doesn't it say the same thing forr1
in which I have providedt1
of type{ a: number }
?The text was updated successfully, but these errors were encountered: