A
A
Alex102142020-12-18 17:47:06
Angular
Alex10214, 2020-12-18 17:47:06

Can a variable be typed as strings or object?

Good day. I have a variable "Simple: any". For me, this variable should be a string by default.
It must be a string because by default it is in the FormControle as setState. But an object can fly into it. Is it possible to type a variable to be a string and an object? And not just the any type?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuriy Vorobyov, 2020-12-18
@YuriyVorobyov1333

You can: And it will be even better if you describe how your object looks like, for example:
Simple: string | Object

{
  field1: string,
  field2: number
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question