QuizNot attempted
Literal inference through an identity generic
1–4 to choose, Enter to submit
Show answer & explanation
Correct answer:
a: 'hello',b: string,c: string
Tis inferred as the literal'hello'(it appears at the top level of the return type, so TS keeps the literal), givinga: 'hello'letwidens that widening literal tostringsobcan be reassigned- an explicit
<string>skips inference entirely. - Not 'all string': inference keeps literal types here.
- Not 'all hello':
letwidens and the explicit argument wins. - Not b: 'hello': a mutable
letbinding widens fresh literal types.