код (ошибка описана комментом в коде):
class SomeClass {
static addr = 'https://example.com/api'
static api = {
testkey: {
userkey: async (apikey: string) => {
this.doRequest('testkey', 'userkey', {})
}
},
anotherPart:{},
}
static async doRequest<res, part extends parts, command extends commands<part>>(apiPart: part, apiCommand: command, params: object): Promise<res> {
// ошибка указывает на то, что apiCommand не может быть неявно преобразован в string
// Implicit conversion of a 'symbol' to a 'string' will fail at runtime. Consider wrapping this expression in 'String(...)'.
const url = new URL(`${this.addr}/${apiPart}/${apiCommand}`)
const resp = await fetch(url, {
method: 'post',
body: JSON.stringify(params),
})
if (!resp.ok) {
throw resp
}
const res = await resp.json()
return res
}
}
type SomeApi = typeof SomeClass['api']
type parts = keyof SomeApi
type commands<part extends parts> = keyof SomeApi[part]