[英]How to define a lambda function with a return type that can be used later with a generic
I have a class using generics like such - 我有一个使用泛型的类-
export class MyClass<T>
{
constructor( private myCallback:()=>T)
{
...
}
}
My callback is a lambda fucntion that returns a new object of type T. I'd like to be able to write code inside MyClass as such 我的回调是一个lambda功能,它返回类型T的新对象。我希望能够像这样在MyClass内编写代码
let t:T = this.myCallback() ;
however i'm running into build errors. 但是我遇到构建错误。 Seems the syntax is broken somewhere but i don't know where.
似乎语法在某个地方坏了,但我不知道在哪里。 Can anyone help?
有人可以帮忙吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.