I am seeking a solution to specify the argument for example
. Currently, the code only sets it to any
. Playground
function clientImport <T extends string>(v: T) {
const resolve = () => import(v)
type ResolveReturn = Awaited<ReturnType<typeof resolve>>
const example = (value: ResolveReturn) => {
return value
}
return {
path: v,
resolve,
example
}
}
const example = async () => {
const { path, resolve, example } = clientImport('./client_code.tsx')
console.log(path)
const v = await resolve()
// ^?
example(v)
// ^?
}
I am looking to type this as follows:
function clientImport <T extends string>(v: T) {
return function <Z>(x: (q: T) => Promise<Z>) {
return {
resolve: () => x(v),
path: v
}
}
}
const v = await clientImport('../examples/client_code/example.ts')(p => import(p))