N
N
Nikolay Matyushkin2020-06-15 16:59:42
typescript
Nikolay Matyushkin, 2020-06-15 16:59:42

A mandatory parameter of 2 optional ones, how can this be described?

There is a type

export type PropsType = {
    param1?: string;
    param2?: string;
};


This is the component type. Either param1 or param2 dynamically comes to the component. Based on the type described above, nothing may come to the component at all, but either param1 or param2 constantly comes to me. Based on this requirement, how can such a type be described?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2020-06-15
@Devilz_1

type param1 = {
    param1: string
};
type param2 = {
    param2: string
};

export type PropsType = param1 | param2;

So?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question