-1
let Obj = function Obj<T>(gen: T) {
return {
data: <{[Key in keyof T]: T[Key]}>{},// need generic, result T[Key]
gen,
}
}({
foo(min: number, max: number, container: { data: any }) {
let res = ((max - min)/2)
container.data.foo = res
return res//number
}
});
Obj.gen.foo(20,50,Obj)
let aaaaaaa: number = Obj.data.foo;//Obj.data.foo typeof function. must be number
Obj.data.foo
の型を取得するためのtypescript genericです。しかし数「関数型の型」(数字)
でなければなりませんscreen shotで見てください - 私はT [キー]
の結果のための一般的な必要
を強調しました。
。
。
更新:
type qqw<R> =() => R
;
function ZcddF<Q>(foo: qqw<Q>): Q {
return ;
}
function foo(): number { return ; }
let aaaa = ZcddF(foo)// 4a is number
;
type a = <Z>(foo: qqw<Z>) => Z
type b =() => number
;
let ff:a;
let bbbb = ff(foo)// 4b is number too
;
// type cccc = a(b) // <------------ QN how get this type/generic