[英]React and TypeScript - Component<Props & {}>
What does this piece of code mean? 这段代码是什么意思?
export class App extends Component<Props & { some: string; some2: string; }>
I mean... what is after the & sign 我的意思是... &符号后面是什么
& { some: string; some2: string; }
It's an intersection type. 这是路口类型。 When defining interfaces in typescript you can separate each property with a semicolon.
在打字稿中定义接口时,可以用分号分隔每个属性。 You can also use commas.
您也可以使用逗号。 It doesn't matter.
没关系
https://www.typescriptlang.org/docs/handbook/interfaces.html https://www.typescriptlang.org/docs/handbook/interfaces.html
export class App extends Component<Props & { some: string; some2: string; }>
Is no different from 没什么不同
interface SomeInterface {
some: string;
some2: string;
}
export class App extends Component<Props & SomeInterface>
It's just written inline instead of creating a new interface for that one line. 它只是内联而不是为该行创建新接口。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.