請問執(zhí)行node 3-1.ts報如下錯誤,問題在哪里?
function add(n1: number, n2: number) {
? ? ? ? ? ? ? ?^
SyntaxError: Unexpected token ':'
如果執(zhí)行tsc? 3-1.ts 沒有問題,執(zhí)行node? 3-1能顯示
function add(n1: number, n2: number) {
? ? ? ? ? ? ? ?^
SyntaxError: Unexpected token ':'
如果執(zhí)行tsc? 3-1.ts 沒有問題,執(zhí)行node? 3-1能顯示
2022-11-08
舉報
2023-07-10
node不支持直接編譯ts文件,安裝ts-node,用ts-node 執(zhí)行就可以了