简体   繁体   中英

How do I define an anonymous generic interface in typescript?

我正在寻找一种无需声明接口即可使以下代码编译的方法。

var a : <A>{ (value: A): void; (): A; } = null; 

It doesn't make sense for a generic type like that to even exist. It's the same reason you can't write Foo<T> x; in C++ without an actual T in scope -- once the type is manifest, it has to be bound.

You can write this instead, which probably has the semantics you wanted anyway.

var a: { <A>(value: A): void; <A>(): A; } = null; 

If that's not what you were looking for, it'd be useful to post some examples of what valid and invalid calls on a would look like.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM