// ts中可以使用 typeof 获取 变量的类型 const str:string = "foo" function echo(arg:typeof str):string { return arg } // 如何获取echo函数的返回值类型? const bar :typeof echo = '1' // ERROR // 不能将类型“"1"”分配给类型“(arg: string) => string”。
翻下文档就能解决的事情
type Bar = string; type foo = () => Bar; type baz = ReturnType<foo>;
548k questions
547k answers
4 comments
86.3k users