kata 2
This commit is contained in:
parent
2023e73eb4
commit
a1dca63a56
66
src/05-forgeschrittenes-typsystem/KATA2/starter.ts
Normal file
66
src/05-forgeschrittenes-typsystem/KATA2/starter.ts
Normal file
@ -0,0 +1,66 @@
|
||||
export {};
|
||||
|
||||
// 1. NonNullableProps
|
||||
type Response = { success: boolean; message?: string };
|
||||
type NonNullableProps<T> = any;
|
||||
type NonNullableResponse = NonNullableProps<Response>;
|
||||
// Erwartet:
|
||||
// { success: boolean; message: string; }
|
||||
|
||||
// 2. ReadonlyExcept
|
||||
type Event = { timestamp: number; type: string };
|
||||
type ReadonlyExcept<T, K extends keyof T> = any;
|
||||
type ReadonlyExceptType = ReadonlyExcept<Event, 'type'>;
|
||||
// Erwartet:
|
||||
// { readonly timestamp: number; type: string; }
|
||||
|
||||
// 3. KeysOfType
|
||||
type Settings = { darkMode: boolean; fontSize: number };
|
||||
type KeysOfType<T, U> = any;
|
||||
type KeysWithBoolean = KeysOfType<Settings, boolean>;
|
||||
// Erwartet: "darkMode"
|
||||
|
||||
// 4. NumberKeys
|
||||
type Employee = { id: number; name: string; salary: number };
|
||||
type NumberKeys<T> = any;
|
||||
type KeysWithNumbers = NumberKeys<Employee>;
|
||||
// Erwartet: "id" | "salary"
|
||||
|
||||
// 5. ReturnTypeOf
|
||||
type FetchFn = () => Promise<string>;
|
||||
type ReturnTypeOf<T> = any;
|
||||
type FetchResult = ReturnTypeOf<FetchFn>;
|
||||
// Erwartet: Promise<string>
|
||||
|
||||
// 6. FilterStrings
|
||||
type Values = { a: string; b: number; c: boolean };
|
||||
type FilterStrings<T> = any;
|
||||
type OnlyStrings = FilterStrings<Values>;
|
||||
// Erwartet:
|
||||
// { a: string; }
|
||||
|
||||
// 7. FunctionKeys
|
||||
type Button = { text: string; onClick: () => void };
|
||||
type FunctionKeys<T> = any;
|
||||
type FnKeys = FunctionKeys<Button>;
|
||||
// Erwartet: "onClick"
|
||||
|
||||
// 8. ToRequired
|
||||
type OptionalFields = { foo?: string; bar?: number };
|
||||
type ToRequired<T> = any;
|
||||
type RequiredFields = ToRequired<OptionalFields>;
|
||||
// Erwartet:
|
||||
// { foo: string; bar: number; }
|
||||
|
||||
// 9. NonFunctionKeys
|
||||
type Logger = { log: () => void; level: string };
|
||||
type NonFunctionKeys<T> = any;
|
||||
type OnlyProps = NonFunctionKeys<Logger>;
|
||||
// Erwartet: "level"
|
||||
|
||||
// 10. NullableStrings
|
||||
type Product = { price: number; name: string };
|
||||
type NullableStrings<T> = any;
|
||||
type NullableProduct = NullableStrings<Product>;
|
||||
// Erwartet:
|
||||
// { price: number; name: string | null; }
|
||||
Loading…
x
Reference in New Issue
Block a user