I am new to typescript.
I have 2 type.
type Point = {
x: number;
y: number;
};
type Label = {
name: string;
};
I have Variable Duko.
let Duko: ? = {...};
How to say that Duko is equal to Label type or Point.
I am new to typescript.
I have 2 type.
type Point = {
x: number;
y: number;
};
type Label = {
name: string;
};
I have Variable Duko.
let Duko: ? = {...};
How to say that Duko is equal to Label type or Point.
Use an union type:
A union type describes a value that can be one of several types. We use the vertical bar (|) to separate each type, so
number | string | boolean
is the type of a value that can be anumber
, astring
, or aboolean
.
Therefore:
let Duko: Point | Label = {...};
Also an interesting read: Typescript: Interfaces vs Types