/* Intro: PowerUsers idea was bad. Once those users got extended permissions, they started bullying others and we lost a lot of great users. As a response we spent all the remaining money on the marketing and got even more users. We need to start preparing to move everything to a real database. For now we just do some mocks. The server API format was decided to be the following: In case of success: { status: 'success', data: RESPONSE_DATA } In case of error: { status: 'error', error: ERROR_MESSAGE } The API engineer started creating types for this API and quickly figured out that the amount of types needed to be created is too big. Exercise: Remove UsersApiResponse and AdminsApiResponse types and use generic type ApiResponse in order to specify API response formats for each of the functions. */
startTheApp((e: Error | null) => { console.log(); if (e) { console.log(`Error: "${e.message}", but it's fine, sometimes errors are inevitable.`) } else { console.log('Success!'); } });
// In case you are stuck: // https://www.typescriptlang.org/docs/handbook/2/generics.html
报错:
1 2 3 4 5 6 7 8 9
index.ts(137,21): error TS2571: Object is of type'unknown'. index.ts(138,48): error TS2571: Object is of type'unknown'. index.ts(140,47): error TS2571: Object is of type'unknown'. index.ts(147,25): error TS2571: Object is of type'unknown'. index.ts(148,43): error TS2571: Object is of type'unknown'. index.ts(150,51): error TS2571: Object is of type'unknown'. test.ts(35,5): error TS2344: Type 'false' does not satisfy the constraint 'true'. test.ts(88,5): error TS2344: Type 'false' does not satisfy the constraint 'true'. test.ts(105,5): error TS2344: Type 'false' does not satisfy the constraint 'true'.
/* Intro: PowerUsers idea was bad. Once those users got extended permissions, they started bullying others and we lost a lot of great users. As a response we spent all the remaining money on the marketing and got even more users. We need to start preparing to move everything to a real database. For now we just do some mocks. The server API format was decided to be the following: In case of success: { status: 'success', data: RESPONSE_DATA } In case of error: { status: 'error', error: ERROR_MESSAGE } The API engineer started creating types for this API and quickly figured out that the amount of types needed to be created is too big. Exercise: Remove UsersApiResponse and AdminsApiResponse types and use generic type ApiResponse in order to specify API response formats for each of the functions. */