Hey typescript, I'm getting an error when instantiating a tagged union whose discriminant property is inlined into the literal, vs. set via assignment right afterwards. Is there something I'm missing here?
TypeScript Version: 2.0.3 (or whatever's on http://www.typescriptlang.org/play/)
Code
interfaceILinearAxis{type: "linear";}interfaceICategoricalAxis{type: "categorical";}typeIAxis=ILinearAxis|ICategoricalAxis;typeIAxisType="linear"|"categorical";functiongetAxisType(): IAxisType{if(1==1){return"categorical";}else{return"linear";}}constbad: IAxis={type: getAxisType()};//TS2322: Type '{ type: "linear" | "categorical"; }' is not assignable to type 'ILinearAxis | ICategoricalAxis'.// Type '{ type: "linear" | "categorical"; }' is not assignable to type 'ICategoricalAxis'.// Types of property 'type' are incompatible.// Type '"linear" | "categorical"' is not assignable to type '"categorical"'.// Type '"linear"' is not assignable to type '"categorical"'.constgood: IAxis={type: undefined};good.type=getAxisType();Expected behavior: Both should work
Actual behavior: The "bad" axis declaration fails with the error described
Thanks!
Hey typescript, I'm getting an error when instantiating a tagged union whose discriminant property is inlined into the literal, vs. set via assignment right afterwards. Is there something I'm missing here?
TypeScript Version: 2.0.3 (or whatever's on http://www.typescriptlang.org/play/)
Code
Expected behavior: Both should work
Actual behavior: The "bad" axis declaration fails with the error described
Thanks!