Skip to content

Instantly share code, notes, and snippets.

@xwartz
Created May 27, 2021 05:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xwartz/9ed79202e3663e9ca912120ba1e64c73 to your computer and use it in GitHub Desktop.
Save xwartz/9ed79202e3663e9ca912120ba1e64c73 to your computer and use it in GitHub Desktop.
interview-type
/**
*
* 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