Implement the built-in ReturnType generic without using it.
type MyReturnType<T extends (arg: any, ...args: any) => any> = T extends (arg: any, ...args: any) => infer R ? R : unknown
3. Omit ๐
Implement the built-in Omit<T, K> generic without using it.Constructs a type by picking all properties from T and then removing K
type MyOmit<T, K extends keyof T> = {[P in keyof T extends K? never: P]: T[P]}
// ์ฐพ์๋ณธ ์ ๋ต
type MyOmit<T, K extends keyof T> = {[P in keyof T as P extends K? never: P]: T[P]}
// tslib
type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;
as์ ๋ํด ๊ณต๋ถ ํ์...
8. Readonly 2 ๐
Implement a generic MyReadonly2<T, K> which takes two type argument T and K.K specify the set of properties of T that should set to Readonly. When K is not provided, it should make all properties readonly just like the normal Readonly.
// ๋ด ๋ต -> error ์์ (omit์ ์ด์ฉํด๋ดค์ผ๋...)
type MyReadonly2<T, K extends keyof T> = { readonly [P in K]: T[P] } & { [P in keyof T as P extends K ? never: P]: T[P]}
// ๋ต์ด ๋๋ ค๋ฉด
type MyReadonly2<T, K extends keyof T = keyof T> = { readonly [P in K]: T[P] } & { [P in keyof T as P extends K ? never: P]: T[P]}
// = keyof T๊ฐ ์ถ๊ฐ๋์ด์ผ ํ๋ค
9. Deep Readonly๐
Implement a generic DeepReadonly which make every parameter of an object - and its sub-objects recursively - readonly.
type DeepReadonly<T> = {
readonly [P in keyof T]: keyof T[P] extends never ? T[P] : DeepReadonly<T[P]>
}
2. Get Return Type โ
Implement the built-in ReturnType generic without using it.
3. Omit ๐
Implement the built-in Omit<T, K> generic without using it. Constructs a type by picking all properties from T and then removing K
as
์ ๋ํด ๊ณต๋ถ ํ์...8. Readonly 2 ๐
Implement a generic MyReadonly2<T, K> which takes two type argument T and K. K specify the set of properties of T that should set to Readonly. When K is not provided, it should make all properties readonly just like the normal Readonly.
9. Deep Readonly๐
Implement a generic DeepReadonly which make every parameter of an object - and its sub-objects recursively - readonly.
10. Tuple to Union โ