-
Notifications
You must be signed in to change notification settings - Fork 12.3k
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
Suspected breaking change with pushing and assigning a 'derived' value into a 'base' array #59016
Comments
The documentation addresses this issue :
// Before
let mySquare = createSquare({ colour: "red", width: 100 });
// Object literal may only specify known properties, but 'colour' does not exist in type 'SquareConfig'. Did you mean to write // 'color'?
// This is the workaround
let squareOptions = { colour: "red", width: 100 };
let mySquare = createSquare(squareOptions); In your case, it seems like the object is undergoing exess property-checks before being assigned to the item2 variable. |
Thanks @REDAMANS Yes I can see the documentation you quote at https://www.typescriptlang.org/docs/handbook/2/objects.html#excess-property-checks, that gives some really helpful context. It seems that the excess property checks have been there for a long time, when passing a value inline as an argument. However the difference in the example you give is that,
In my example, passing If I go to 4.9.5, and try and add a property plucked out of thin air, the inline assignment does correctly error so I think there is a difference between
and in 4.9.5, 2. was allowed when pushing values inline into an array, and now it is not allowed. |
Interestingly, in 4.9.5 the In 5.0.4, it gives 2 errors, that it doesn't exist in type Derived or Base. So it does still seem to be aware of the fact that there is a Derived type. It is just then on the one above, which does match Derived, it gives 1 out of 2 errors, still erroring for Base. |
Bisects to #52282 FWIW If this can be fixed simply we can take a PR, but assignment expressions in this position are pretty rare and I don't think we'd want to do anything that breaks other more mainline scenarios as a trade-off. |
π Search Terms
inline assignment array derived base push 'Object literal may only specific known properties'
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.0.4#code/JYOwLgpgTgZghgYwgAgEJwM4oN4FgBQyywAJgFzIgCuAtgEbQDcBAvgQaJLIigCLTAAbhBLIIAD0ggSGNJhwEiIODQgUMYKKADmzfG3wEEAexAbikGhgrosAbQC6yALzJHeggBsIYCxBoAjBT8WsIket6+wJYATMECYR740f4BLsjYxOTIAQA0lCpqyADkYAAWwLKVyMYA1shQENpwUCTeGBjFyCx6KVYAdAAOVBhlABR9AQCUSX0YQyPjE7HpmaQUMfnKqhSlFVWyAHIA8gAqNfWgyACs-QAM-QAs+XRUUbJ1xCDIj-0AnP1rl0WFMZkA
π» Code
π Actual behavior
'Object literal may only specific known properties' error
π Expected behavior
The code should not produce an error
Additional information about the issue
It is possible that this is a change to the order in which types are inferred, but I have been unable to find any details in the documentation/changelog.
The text was updated successfully, but these errors were encountered: