zhminjian 2022-05-12 15:19 采纳率: 28.6%
浏览 53
已结题

const greeting:string="abc" 为什么会报错

第一次使用TS。一个很简单的语句就报错,就是给常量加了个类型。
string及 {x:number,y:number}及{x:number}都会报错的

const greeting:string="abc";
const temp:{x:number,y:number}={x:5,y:6};
console.log(temp);
//@ts-ignore
const point:{x:number}={x:88};
console.log(point);

报错信息:
C:\Program Files\nodejs\node.exe .\hello-world.ts
Process exited with code 1
Uncaught SyntaxError d:\VUE-test\typescript_tt\hello-world.ts:1
const greeting:string="abc";
^

SyntaxError: Missing initializer in const declaration
at compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1032:15)
at Module._compile (node:internal/modules/cjs/loader:1067:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Module._load (node:internal/modules/cjs/loader:822:12)
at executeUserEntryPoint (node:internal/modules/run_main:77:12)
at (node:internal/main/run_main_module:17:47)
没有可用的调试程序,无法发送“variables”

  • 写回答

5条回答 默认 最新

  • zhminjian 2022-05-12 15:28
    关注

    用的工具是VS-CODE

    谢谢各位了。TS不能直接运行,先进行编译成js后才能运行。不是像其他语言那样,直接运行。

    评论 编辑记录

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 5月12日
  • 创建了问题 5月12日

悬赏问题

  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败