You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sigh... I really wish the wording of this error message would be changed.
This isn't a bug. The excess property check error is not a type error, it's a lint check. You can't rely on it to prevent extra properties from being put on an object because it won't always trigger (which is by design). If that's what you need, see #12936.
The other issue you linked to this (#49511) is unrelated - there is nothing like an any involved here. { a: number, b: number } is a legal subtype of and assignable to { a: number }.
Sigh... I really wish the wording of this error message would be changed.
This isn't a bug. The excess property check error is not a type error, it's a lint check. You can't rely on it to prevent extra properties from being put on an object because it won't always trigger (which is by design). If that's what you need, see #12936.
The other issue you linked to this (#49511) is unrelated - there is nothing like an any involved here. { a: number, b: number } is a legal subtype of and assignable to { a: number }.
The focus of this issue is not on whether additional attributes can be added,
Is difference types of b.data and c.data by use getters b.data and c.data should throw errors simultaneously or not
You are conflating two different things. The autocomplete thing is unrelated to the type checking of c.data.
b.data and c.data should throw errors simultaneously or not
No, they shouldn't; it's already been explained several times why c.data doesn't have an error. The excess property check doesn't apply to it, but it's still type-checked properly. For example if you change the code to
You are conflating two different things. The autocomplete thing is unrelated to the type checking of c.data.
b.data and c.data should throw errors simultaneously or not
No, they shouldn't; it's already been explained several times why c.data doesn't have an error. The excess property check doesn't apply to it, but it's still type-checked properly. For example if you change the code to
constc: T={getdata(){return42;},};
then you get a type error.
Thank you, I understand my mistake
The real problem should be automatic completion
The problem of automatic completion made me think that c.data had changed to any type, resulting in the loss of type checking
Activity
whzx5byb commentedon May 9, 2024
See https://github.com/microsoft/TypeScript/wiki/FAQ#indirect-excess-properties-are-ok
lqzhgood commentedon May 9, 2024
bug
b.data.bthrow type error. and inc.datano type prompt likeany,see typescirpt palay
https://www.typescriptlang.org/play/?#code/C4TwDgpgBAKlC8UDeAoKUAmBDYWBcya6U+UAdgK4C2ARhAE4DcRAvs2yigMYD2ZAzsCg0CcRKnTZcBCcVIBGAEwBmJcoA0RdCKjKALAfXEoAehNRgAC3o8A7hfDQGN+q00dufQVC6iEhdABzCCEpLAAKAEoA4noQinoyGOMFFU1jbQJlbKMzch4hKxt7UEgoZx5XYw50FndmTl4BUP9ZYNCcCOjZdDjgBKSeuQI1dIydbOUoLSga2frOUuhgDH8lngAzSUZTcyQSPEpaBiMRI7p6WaA
fatcerberus commentedon May 9, 2024
Sigh... I really wish the wording of this error message would be changed.
This isn't a bug. The excess property check error is not a type error, it's a lint check. You can't rely on it to prevent extra properties from being put on an object because it won't always trigger (which is by design). If that's what you need, see #12936.
The other issue you linked to this (#49511) is unrelated - there is nothing like an
anyinvolved here.{ a: number, b: number }is a legal subtype of and assignable to{ a: number }.snarbies commentedon May 9, 2024
Indirect excess properties are not an error. Examples of indirect excess properties would be:
bis direct. You go straight from value→property.cin indirect because it is one step removed. You have a getter, which is a function that returns a value.From the linked FAQ, excess property checks are to defend against things like typos:
But there are plenty of situations where you want or need to allow extra properties.
whzx5byb commentedon May 9, 2024
When inspecting the code I do find something looks like a bug: #58484.
lqzhgood , is it what you are talking about?
lqzhgood commentedon May 9, 2024
The focus of this issue is not on whether additional attributes can be added,
Is difference types of
b.dataandc.databy usegettersb.dataandc.datashould throw errors simultaneously or notlqzhgood commentedon May 9, 2024
yes,
d.dataandc.data(getter) Inconsistent types returned,(from the perspective of throwing exceptions)and
c.datalooks likeanyin autocompletelqzhgood commentedon May 9, 2024
Thank you for your answer, but
c.datalook likeanyin autocomplete.https://www.typescriptlang.org/play/?#code/C4TwDgpgBAKlC8UDeAoKUAmBDYWBcya6U+UAdgK4C2ARhAE4DcR6AXuwZbQ8+gL7MBKFAGMA9mQDOwKDQJxEqdNlwElxUgEYATAGYdugDQtZBXQBZLh4lAD0tqMAAW9MQHdH4aA1f0T7VgIDIj5jIVEJaSgReQRCdABzCBkVLAAKAEp44npkinoybJstPWMbdDkoXWrre3IxGWdXD1BIKB8xP3KodhMhfjDmYXEpFLj1JJScdKz1dFzgfMK5jSDSkwqzaqg+3ihQlHDW6GAMOOOxADNlRjsHJBI8Ljp6azlnhn2gA
fatcerberus commentedon May 9, 2024
You are conflating two different things. The autocomplete thing is unrelated to the type checking of
c.data.No, they shouldn't; it's already been explained several times why
c.datadoesn't have an error. The excess property check doesn't apply to it, but it's still type-checked properly. For example if you change the code tothen you get a type error.
lqzhgood commentedon May 9, 2024
Thank you, I understand my mistake
The real problem should be automatic completion
The problem of automatic completion made me think that
c.datahad changed toanytype, resulting in the loss of type checkingfatcerberus commentedon May 9, 2024
In that case, this is a retroactive duplicate of #58484 😄
lqzhgood commentedon May 9, 2024
the real problem is #58484. I will close this issue