gpt4 book ai didi

javascript - Typescript -w(watch) 在我的安装中不起作用

转载 作者:搜寻专家 更新时间:2023-10-30 21:12:35 24 4
gpt4 key购买 nike

我已经安装了 Typescript 2.0.6,我也在安装 Node 。如果我尝试用“-w”在监视模式下编译一个文件,它是行不通的。它会引发以下错误。

ts5001: the current host does not support the '--watch' option

使用以下命令编译我的 typescript 文件“index.ts”

tsc -w index.ts

如果知道请帮我看看如何在 watch 模式下编译代码。

最佳答案

2021 年的更新答案

有一个内置的--watch/-w 选项见the TS compiler options (在列表的最后)。

或者一旦您使用 outDirrootDir 设置了 tsconfig.json:

{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */

/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "ES2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "ES2020", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
"outDir": "src/main/resources/static/js", /* Redirect output structure to the directory. */
"rootDir": "src/main/resources/static/ts" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
}
}

然后你就可以打电话了

tsc --watch

第二个选项我还没有亲自尝试过,但它是另一种用于文件监视的选项,请参阅 Configuring Watch有关详细信息,但这里有来自官方网站的示例 tsconfig.json 设置:

{   // Some typical compiler options   
"compilerOptions": {
"target": "es2020",
"moduleResolution": "node"
// ... },

// NEW: Options for file/directory watching "watchOptions": {
// Use native file system events for files and directories
"watchFile": "useFsEvents",
"watchDirectory": "useFsEvents",

// Poll files for updates more frequently
// when they're updated a lot.
"fallbackPolling": "dynamicPriority"
}
}

关于javascript - Typescript -w(watch) 在我的安装中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40650803/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com