Created
May 27, 2021 05:23
-
-
Save xwartz/9ed79202e3663e9ca912120ba1e64c73 to your computer and use it in GitHub Desktop.
interview-type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* Complete the following 2 types of 'CreateRequest' and 'GetParams'. | |
* 完善下述两个类型 'CreateRequest' 和 'GetParams'。 | |
* | |
**/ | |
// improve type of CreateRequest | |
type CreateRequest = unknown | |
const createRequest: CreateRequest = (str) => { | |
return { | |
[`get${str}`]: () => Promise.resolve([]), | |
[`create${str}`]: () => Promise.resolve([]) | |
} | |
} | |
const { getUsers, createUsers } = createRequest('users') | |
// improve type of GetParams | |
type GetParams = unknown | |
type P1 = GetParams<(p: string) => void> // -> [string] | |
type P2 = GetParams<(a: string, b: number) => void> // -> [string, number] | |
type P3 = GetParams<string> // -> never |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment