0

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; }
2
  • It's an inline type, with keys some and some2 as strings. Commented Mar 6, 2019 at 22:44
  • but why there are ";" signs? Why not ","? This is not a part of the interface? Commented Mar 6, 2019 at 22:46

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

0
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.