`import type {Node} from 'react';` 和 App 中的用法是什么:() => Node

What does `import type {Node} from 'react';` and usage in App: () => Node

运行 这个命令:

npx react-native init AwesomeProject

App.js 文件中我不明白 2 行:

import React from 'react';
import type {Node} from 'react';  // 1
import {
  SafeAreaView,
  ScrollView,
 // ..... Code .... 

const App: () => Node = () => {  // 2
   // ..... Code .... 


export default App;
  1. 导入类型节点

    按照,我了解到这样的导入是用来导入一个类型的对象,例如:

    import type { Array, Object, ... } from 'wherever';
    

    老实说我更关心下一点(可能如果我明白我也会自动得到这个)。

  2. const App: () => Node = () =>

    我所看到的只是 App 是一个 变量,它引用了一个函数,该函数 returns 一个 Node 类型的对象 Object 也是一个函数。它是否将应用程序包装到 'React' 实例或其他东西中?

What does const App: () => Node = () => do and why you would want to use it?

如果我们删除类型,代码为:

const App = () => {
  // ... code
}

这是一个 React 功能组件。

然后在上面添加一个类型:() => Node。这意味着它是一个不带参数的函数,并且 returns 反应 Node。类型通过让计算机更好地分析代码并更快地指出错误(甚至在 运行 代码之前)

来帮助开发