In Typescript I have two classes, Foo and Bar
export class Foo{
data: Bar<Types>
}
export class Bar<T>{
attributes: T
}
Next to that I also have a type
export type Types = Circle | Square
Next up I declare my variable
x: Bar<Circle>
But when I want to assign a value to this variable by doing
x = someRandonJsonData
I get the following type error:
Type 'Bar<Types>' is not assignable to type 'Bar<Circle>'.
I'm wondering where my mistake is in all of this ?
someRandonJsonData. If it isBar<Types>this error is expected.. and it's there for the same reason you can't assign a value of typeTypesto a variable of typeCircleBar<Types>. So how would I be able to make myBarproperty attributes to either beCircleorSquare?