【发布时间】:2021-07-07 13:27:54
【问题描述】:
我有一个名为 main.ts 的文件,其中包含以下代码 sn-p :
interface bodyInfos {
height?: any;
mass?: any;
}
const calculateBmi = (user: bodyInfos) => {
return user.mass / ( user.height ** 2 );
};
let foo: bodyInfos;
let bar: bodyInfos;
// Foo
foo.height = 172;
foo.mass = 75;
// Bar
bar.height = 180;
bar.mass = 90;
console.log('foo BMI', calculateBmi(foo) );
console.log('bar BMI', calculateBmi(bar) );
问题是每当我尝试使用以下命令执行文件 main.ts 时:node main.ts 我在控制台上收到错误消息:
interface bodyInfos {
^^^^^^^^
SyntaxError: Unexpected identifier
我需要你的支持。
【问题讨论】:
-
Node 默认不运行 TS 代码。您需要将其编译为 JavaScript 并运行它。
标签: javascript typescript interface