Passing a Meta / Tag object when extending a class. What is this syntax and what does it do?

I just started my first reaction project and came across a strange syntax that I have not seen so far (at least in the javascript context).

Does this come from a reaction, a native reaction or ecma6? And more importantly: what it defines:

export default class App extends Component<{}> {
    // class code
}

I am confused about this part: <{}>

The tokens <and> make me suggest that this is due to the reaction, but I can be wrong, as I recall this in other languages ​​before.

Please enlighten me :-)

+4
source share
1 answer

Welcome to the wonderful world of static analysis!

, , - flow. Flow - , javascript. Javascript - . , - .

let name = 'Kyle';
name = 4; // We just assigned a number to a string

Javascript , , , , name .

javascript-. , . , .

let name: string = 'Kyle'

, , , ;

name = 4;

enter image description here

! Flow , .

, native.

, , , .

// @flow

, , . . , - , . , , .

, , .

class NamePrinter extends React.Component<{}> {
  render() {
    return <Text>{this.props.name}</Text>
  }
}

.

type NamePrinterProps = {
  name: string;
}

// Change our example to use the typing

class NamePrinter extends React.Component<NamePrinterProps>

, NamePrinter , .

class App extends React.Component<{}> {
  render() {
    return <NamePrinter name={4}/>
  }
}

enter image description here

! javascript! . Typescript, .

- https://flow.org/en/

Typescript - https://www.typescriptlang.org

+4

Source: https://habr.com/ru/post/1687542/


All Articles