0

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.

1 Answers1

2

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 a number, a string, or a boolean.

Therefore:

let Duko: Point | Label = {...};

Also an interesting read: Typescript: Interfaces vs Types

pzaenger
  • 11,381
  • 3
  • 45
  • 46
  • 1
    your example is not what i want. [Look what i want](https://codesandbox.io/s/typescript-91lle) –  Aug 23 '19 at 12:47