QuizNot attempted
Structural typing surprise
1–4 to choose, Enter to submit
Show answer & explanation
Correct answer:
- (1) compiles, (2) errors (excess property check on fresh object literals)
- TS is structural, so
raw(which has at leastname: string) is a validUserin (1) - excess property checks run only on fresh object literals written directly at the assignment, so
passworderrors in (2). - Not both compile: misses the excess property check.
- Not both error: extra properties on a non-literal are fine.
- Not (1) errors, (2) compiles: exactly backwards.