Advanced Types — Mapped, Conditional and Template Literal — Concept Check
Questions on Advanced Types — Mapped, Conditional and Template Literal. The type system is itself a small functional language. You will read far more of this than you write, and knowing the syntax is what makes library types comprehensible.
Questions in this quiz
7 questions on Advanced Types — Mapped, Conditional and Template Literal — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.Given a type `User` with properties `name` (string) and `age` (number), which mapped type will create a type with methods `getName` and `getAge`?
- APartial<User>
- BGetters<User>
- CNullable<User>
- DReadonly<User>
2.You have a type `T` that is either `string` or `null`. Which conditional type will result in `never` for `null` values?
- AIsArray<T>
- BElementOf<T>
- CUnwrap<T>
- DNoNull<T>
3.A developer uses `type A = ReturnType<() => string>`. What will be the type of `A`?
- Aunknown
- B() => string
- Cvoid
- Dstring
4.You have a type `Path` defined as `/learn/${Track}`. If `Track` is `'dsa' | 'java'`, what are the possible values for `Path`?
- A'/learn/track'
- B'/learn/dsa' | '/learn/java'
- C'/learn/easy' | '/learn/hard'
- D'/learn/${Track}'
5.A type `T` is `Promise<string>`. Using `Unwrap<T>`, what will be the resulting type?
- APromise<string>
- Bstring
- Cunknown
- Dvoid
6.A type `Combo` is defined as `${Track}-${Level}`. If `Track` is `'dsa' | 'java'` and `Level` is `'easy' | 'hard'`, how many combinations are possible?
- A8
- B6
- C4
- D2
7.What does the mapped type `type Mutable<T> = { -readonly [K in keyof T]: T[K] }` achieve?
- AAdds readonly modifiers
- BRemoves readonly modifiers
- CConverts all types to nullable
- DMaps keys to never