TypeScript · Junior · Question 32 of 75

What is structural typing in TypeScript?

Explanation

If an object has all the properties a type requires, it fits - even if its type has a different name (duck typing). That's why Point2D and Vector2D with the same fields are interchangeable. Nominal behavior can be emulated with branded types.

Further reading

Problem with a question

TypeScript · Junior · question 32

Test yourself

Take the TypeScript · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz