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
T wider in lazy branch of T | (() => T) for known T #55277
typeOptionallyLazy<T>=T|(()=>T)typeMyType={a: boolean}constfn=(t: OptionallyLazy<MyType>)=>{}fn({a: true,shouldFail: 'it does, good'})fn(()=>({a: true,shouldFail: 'this does not fail, which is bad'}))
🙁 Actual behavior
No type error for shouldFail on last line above.
🙂 Expected behavior
Type error for shouldFail on last line above, same as line above it.
() => MyTypeWithExtraProps is assignable to () => MyType, so this is working as intended. The error you see in the first case is due to the excess property check (EPC), which only applies to object literals directly assigned to a type. The error message for EPC is currently misleading; see #55152.
Objects are allowed to have additional properties, however special checks are applied in some locations just to catch probable bugs. As said in other places, this is more of a warning than a type error.
Ahh, appreciate the notes. I wish the error message for those checks were more clear they are a lint, and not a type system property. I've been operating under this misunderstanding for years writing TS!
Any known good workarounds? I guess I can write a Lint rule to require annotation of a lazy value? This caused a very insidious misspelling bug.
Ahh, appreciate the notes. I wish the error message for those checks were more clear they are a lint, and not a type system property. I've been operating under this misunderstanding for years writing TS!
Any known good workarounds? I guess I can write a Lint rule to require annotation of a lazy value? This caused a very insidious misspelling bug.
Thanks again.
I don't see any option other than explicit typings. There is an open suggestion (#12936) for Exact types that are always checked this way, maybe one day that will happen.
I wish the error message for those checks were more clear they are a lint, and not a type system property. I've been operating under this misunderstanding for years writing TS!
You’re certainly not alone. Thats why I’m glad for #55152.
Activity
fatcerberus commentedon Aug 5, 2023
() => MyTypeWithExtraPropsis assignable to() => MyType, so this is working as intended. The error you see in the first case is due to the excess property check (EPC), which only applies to object literals directly assigned to a type. The error message for EPC is currently misleading; see #55152.RobertSandiford commentedon Aug 5, 2023
Discussed in some detail here #55113
Objects are allowed to have additional properties, however special checks are applied in some locations just to catch probable bugs. As said in other places, this is more of a warning than a type error.
Handbook: excess-property-checks
pckilgore commentedon Aug 5, 2023
Ahh, appreciate the notes. I wish the error message for those checks were more clear they are a lint, and not a type system property. I've been operating under this misunderstanding for years writing TS!
Any known good workarounds? I guess I can write a Lint rule to require annotation of a lazy value? This caused a very insidious misspelling bug.
Thanks again.
RobertSandiford commentedon Aug 5, 2023
I don't see any option other than explicit typings. There is an open suggestion (#12936) for Exact types that are always checked this way, maybe one day that will happen.
fatcerberus commentedon Aug 5, 2023
You’re certainly not alone. Thats why I’m glad for #55152.