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
{{ message }}
Repository navigation
Generic return type of function is enforced inconsistently in some casesΒ #51706
I receive no errors for the function definition for the function that explicitly returns the record infered in the assigmnet above but I do for returns without interum assignment
π Expected behavior
I should receive errors for both cases or the behaviour should atleast be consistant
The error is detected by excess property check, which only works for directly assigned object literals. Outside of that, the object with a non-number property is otherwise assignable to the numeric record. See #48906.
Yeah, sorry I wasnβt clear above - this is working as intended. Objects can have more properties than their type requires, the compiler just does an excess property check in certain cases as a kind of basic sanity check but you shouldnβt rely on it to enforce runtime safety.
Activity
fatcerberus commentedon Dec 1, 2022
The error is detected by excess property check, which only works for directly assigned object literals. Outside of that, the object with a non-number property is otherwise assignable to the numeric record. See #48906.
NICHTJ3 commentedon Dec 1, 2022
Pretty similar to #51680 and #48906. If you guys are okay with it I might close as a duplicate? π€
fatcerberus commentedon Dec 1, 2022
Yeah, sorry I wasnβt clear above - this is working as intended. Objects can have more properties than their type requires, the compiler just does an excess property check in certain cases as a kind of basic sanity check but you shouldnβt rely on it to enforce runtime safety.