考虑一下:
function doIt(thing: SomeThing, iterations: number): void { // ... } class ThingProcessor{ private state: { // how to avoid specifying the arguments again? action: (thing: SomeThing, iterations: number) => void }; }
在这个例子中,我必须指定 doIt 函数参数两次。我宁愿表明 state.action 是 typeof(doIt) ,例如,使用与 多伊特 功能。
doIt
state.action
typeof(doIt)
多伊特
你可以使用 typeof 函数上的运算符以获取其类型
typeof
function doIt(thing: SomeThing, iterations: number): void { // ... } class ThingProcessor { private state: { // how to avoid specifying the arguments again? action: typeof doIt; }; }