简体   繁体   English

在 Typescript 中转换 React Native 导出文件

[英]Transform React Native export file in Typescript

How can I translate this.js file into a Typescript one?如何将 this.js 文件转换为 Typescript 文件?

import * as Colors from './colors';
import * as Spacing from './spacing';
import * as Typography from './typography';
import * as Mixins from './mixins';

export { Typography, Spacing, Colors, Mixins };

Thank you谢谢

Edit 1: I'm trying to fix the folowing error:编辑1:我正在尝试修复以下错误:

Cannot find module '_styles' or its corresponding type declarations.找不到模块“_styles”或其相应的类型声明。

When trying to import a file in another file尝试将文件导入另一个文件时

import {Colors,Typography,Mixins} from '_styles';

It works, but shows the above warning.它有效,但显示上述警告。 I have a setup that allow my to import the file without the complete path that works well but with typescript, it shows a warning.我有一个设置,允许我在没有完整路径的情况下导入文件,但使用 typescript,它会显示警告。

Edit 2:编辑2:

I have the following setup in.babelrc我在.babelrc 中有以下设置

    {
  "plugins": [
    [
      "module-resolver",
      {
        "cwd": "babelrc",
        "root": ["./src"],
        "extensions": [".js", ".ios.js", ".android.js", ".ts", ".tsx", ".json"],
        "alias": {
          "_assets": "./src/assets",
          "_components": "./src/components",
          "_atoms": "./src/components/atoms",
          "_molecules": "./src/components/molecules",
          "_organisms": "./src/components/organisms",
          "_navigations": "./src/navigations",
          "_scenes": "./src/scenes",
          "_services": "./src/services",
          "_styles": "./src/styles",
          "_utils": "./src/utils",
          "_i18n": "./src/i18n"
        }
      }
    ]
  ]
}

From TS 3.8 the new syntax is introduces export * as ns from '...'从 TS 3.8 开始,新语法引入了export * as ns from '...'

How about use this?这个怎么用?

export * as Colors from './colors';
export * as Spacing from './spacing';
export * as Typography from './typography';
export * as Mixins from './mixins';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM