[英]Typescript - function return type in interface
试图做到这一点
interface SomeInterface {
someProperty: string | () => JSX.Element
}
该属性应该是返回JSX.Element
的string
或Function
。 如果有的话,正确的语法是什么?
目前我正在做以下作为一个比没有更好的解决方案,但这不是我想要的
interface SomeInterface {
someProperty: string | Function
}
是的,括号是正确的:
interface SomeInterface {
someProperty: string | (() => JSX.Element)
}
declare const s: SomeInterface
if (typeof s.someProperty === 'function') {
s.someProperty() // JSX.Element
} else {
s.someProperty // string
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.