2

我的导入不正常工作。我是角度的新手。

我的程序很简单。我有 2 个文件:

客户.ts

class Person {
  constructor(protected name: string, private age: number) {}

  welcome(): string {
    return `Witaj ${this.name}, czy masz ${this.age} lat?`;
  }
}


export class Customer extends Person {
  constructor(name: string, age: number, private advisor: string) {
    super(name, age);
  }

  welcome(): string{
    return `Siema ${this.name}`;
  }
}

例子.ts

import {Customer} from "./customer";
let jan = new Customer("Jan", 44, "Agata");
console.log(jan);

我的命令是: ts-node sandbox/example.ts 所有文件都在沙箱文件夹中。

SyntaxError: Unexpected token {
at new Script (vm.js:79:7)
at createScript (vm.js:251:10)
at Object.runInThisContext (vm.js:303:10)
at Module._compile (internal/modules/cjs/loader.js:656:28)
at Module.m._compile (/usr/local/lib/node_modules/ts-node/src/index.ts:439:23)
at Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Object.require.extensions.(anonymous function) [as .ts] (/usr/local/lib/node_modules/ts-node/src/index.ts:442:12)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
4

2 回答 2

0

我认为问题出在您的 ts-node 版本上。

因为我无法重现这个问题。

节点:9.8.0

npm:6.4.1

ts节点:7.0.1

于 2018-11-23T09:53:53.353 回答
-1

嘿在这里检查:(在控制台上)

https://stackblitz.com/edit/typescript-4xqc14?file=index.ts

希望这可以帮助!

于 2018-11-23T10:07:52.233 回答