打字稿导入不起作用

typescript import doesn't work

我试图解决这个问题已经超过6-8个小时了。 我认为问题之一是我的英语。 =)

我使用 atom 编辑器、electron、typescript、react

tsconfig.json

{
    "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "moduleResolution": "node",
        "isolatedModules": false,
        "jsx": "react",
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "declaration": false,
        "noImplicitAny": false,
        "noImplicitUseStrict": false,
        "removeComments": true,
        "noLib": false,
        "preserveConstEnums": true,
        "suppressImplicitAnyIndexErrors": true
    },
    "exclude": [
        "node_modules",
        "typings/browser",
        "typings/browser.d.ts"
    ],
    "compileOnSave": true,
    "buildOnSave": false,
    "atom": {
        "rewriteTsconfig": false
    }
}

app.ts:

import {hello} from "./func";
hello("TypeScript");

func.ts

export function hello(name: string){
    console.log(`Hello, ${name}`);
}

启动electron报错:

Uncaught SyntaxError: Unexpected token import

然后,创建文件 react-test.ts:

import * as React from "react";

原子编辑器出现错误:

Cannot find module 'react'

问题: 我不想要更多的理论。有一个具体的例子。请帮我解决。顺便说一下,我对 babel 没有任何问题 =)

更新#1:

电子运行命令:

npm start

项目 github

首先,您需要使用 tsc 命令将 TypeScript 转换为 JavaScript,并且在 index.html 文件中需要 app.js 而不是 app.ts。然后 运行 电子与 npm start