TypeScript Version:
1.8.2
Code
interfaceFoo{ok:string;okToo: number;notOk: "o"|"k";}interfaceBar{bar: string;}interfaceFooBarextendsFoo,Bar{}functionmix<T>(obj:T): T&Bar{(objasany).bar="bar";returnobjasT&Bar;}varfooBar:FooBar=mix({ok:"ok",okToo: 42,notOk:"k"});Expected behavior:
The assignment to fooBar should be allowed.
Actual behavior:
I get the totally confusing error:
Error:(20, 5) TS2322: Type '{ ok: string; notOk: string; } & Bar' is not assignable to type 'FooBar'.
Type 'Bar' is not assignable to type 'FooBar'.
Property 'ok' is missing in type 'Bar'.
The confusing part is that it complains about the first property (ok) and not about notOk.
Looking at the error message it seems that the string literal type notOk:"o"|"k" was converted to notOk :string.
Therefore when I turn the string literal type to a string (notOk:string) everything is OK....
Hint: defining the string literal type as a type does not solve the problem:
typeNotOK="o"|"k";interfaceFoo{//...notOk: NotOK;}//...
TypeScript Version:
1.8.2
Code
Expected behavior:
The assignment to
fooBarshould be allowed.Actual behavior:
I get the totally confusing error:
The confusing part is that it complains about the first property (
ok) and not aboutnotOk.Looking at the error message it seems that the string literal type
notOk:"o"|"k"was converted tonotOk :string.Therefore when I turn the string literal type to a string (
notOk:string) everything is OK....Hint: defining the string literal type as a type does not solve the problem: