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
Can assign types even though interface field overriden using Omit #36604
Omit field override intersection assign missing error
Expected behavior:
If I use Omit and an intersection to override a field within an interface, when I assign an object of new type to original type I am expecting that typescript would give an error.
For example, in the example below, I expect to see a compile error in the line x = v;
But unfortunately there isn't.
However, assigning the field explicitly between the 2 types does give an error.
interfaceTo{field?: number;anotherField: string;}typeFrom={field: null}&Omit<To,'field'>functionfoo(v: From){letx: To;x=v;// expect to have an error but there isn'tx.field=v.field;// Type 'null' is not assignable to type 'number | undefined'}
seems to be solved by switching to the Nightly build of TS which I assume includes the changes in the 3.9 beta, which claims to have this fixed via #37195
seems like one step closer to fixing gaps between types and interfaces, like I brought up in #24970
Activity
ilogico commentedon Feb 4, 2020
It's funny, you can get the correct behavior with:
ekilah commentedon Apr 1, 2020
thanks for this, just ran into it as well. playground link
seems to be solved by switching to the
Nightlybuild of TS which I assume includes the changes in the 3.9 beta, which claims to have this fixed via #37195seems like one step closer to fixing gaps between types and interfaces, like I brought up in #24970