1
interface Person { name: string };

let person : Person = { name: "John Smith" };

let empt: {} = person;

I don't really understand the idea why typescript allow the above code to be compiled, isn't that {} means it doesn't contain any properties, but Person has one property name, {} obviously doesn't contain a property name called name, how Person type can be assignable to an empty type?

2
  • See ms/TS#44874 and the question(s) linked above Commented Jul 10, 2023 at 1:01
  • {} is an object type without properties which (or: whose type) you care about. Commented Jul 10, 2023 at 1:13

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.