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
typeMyObject={[index:string]: MyObject|Function|"wtf"}letmyObj: MyObject;// compilesmyObj={name: "wtf",};// compiles - note the nested key is `notName:`, instead of `name:`myObj={wrapper: {notName: "wtf",},};// as soon as I change the nested key to `name:`, it fails to compile:/*Type '{ name: string; }' is not assignable to type 'Function | MyObject | "wtf"'. Type '{ name: string; }' is not assignable to type '"wtf"'*/myObj={wrapper: {name: "wtf",},};// Other weirdness, if I remove `Function` from the union, it compiles:typeMyObjectNoFunction={[index:string]: MyObjectNoFunction|"wtf"}letmyObjNoFn: MyObjectNoFunction={wrapper: {name: "wtf"}};// More weirdness, if I don't include es6 in my tsconfig, everything compiles
Maybe this is because Function has a name property in es6, so TypeScript infers that { name: "something" } is an unfinished Function type declaration -thedayturns
Playground Link: .
I couldn't get it to happen in playground, but here's a full example on github
Related Issues:
The text was updated successfully, but these errors were encountered:
The issue here is that string index signature in Idx does not participate in contextual type of property x and thus { x: "lit" } gets widened to { x: string }.
TypeScript Version: 3.0.1
Search Terms: typescript compilation function name key union es6 compile error
Code
full example on github .
wtf.ts
tsconfig.json
Expected behavior:
no compilation errors
Actual behavior:
compilation error:
Corresponding stackoverflow:
Playground Link: .
I couldn't get it to happen in playground, but here's a full example on github
Related Issues:
The text was updated successfully, but these errors were encountered: