为了尝试将我的.ts源文件与.js输出分开,我试图在TypeScript中实现一个正式的文件监视器,似乎不存在为单个文件指定输出路径的能力.
这个流程,只是要清楚:我开始观察我的整个src目录,进行更改,比方说,src/views/HomeView.ts我希望节点获取文件已被更改,并将编译后的版本移动到public/js/views/HomeView.js.
使用tsc myfile.ts --out myfile.js它遍历所有模块,并在.ts文件所在的相同路径中编译每个模块,而不将最终文件放在正确指定的路径中.但它会创建一个空文件,我希望它最终结束.
我在想:
1)是否可以使用该--out参数并仅编译该文件?我不希望它遍历导入并编译每个文件,而只是在编译时进行语法/错误检查(这只是次要要求,不是必需的); 和
2)编译器中是否存在阻止其正确组合/创建文件的错误?同样,--outpath指令中的最终输出为空,但确实创建了一个文件.
任何帮助,将不胜感激.
*更新*
虽然我不想关闭这个问题,因为我认为它仍然是一个问题,但我继续实施核心TypeScript编译器以实现我需要做的事情,tsc完全绕过.有关更多信息和用法,请参阅https://github.com/damassi/TypeScript-Watcher.
我意识到我可以编译我的应用程序,tsc my_app.ts --target system它将为每个导入的模块生成一个SystemJS包装文件,这很棒,但它生成匿名(无名)函数,所以我不能只将它们连接到一个文件.
我想过提出这个问题"如何将TypeScript编译为命名的SystemJS模块",但我的目标只是将我的Angular2应用程序编译为单个文件SystemJS.
我在Angular5项目中有这个import语句:
import {plugins, SCECodeGenType} from 'sce-plugins/code-generation';
Run Code Online (Sandbox Code Playgroud)
这解析了我的文件系统上的这个路径:
/Users/.../suman-chrome-extension/node_modules/sce-plugins/code-generation/index.d.ts
Run Code Online (Sandbox Code Playgroud)
在构建应用程序时ng build -w,我收到此错误:
ERROR in ../sce-plugins/code-generation/index.ts Module build failed: Error: /Users/alexamil/WebstormProjects/oresoftware/sumanjs/sce-plugins/code-generation/index.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
at AngularCompilerPlugin.getCompiledFile (/Users/alexamil/WebstormProjects/oresoftware/sumanjs/suman-chrome-extension/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:662:23)
at plugin.done.then (/Users/alexamil/WebstormProjects/oresoftware/sumanjs/suman-chrome-extension/node_modules/@ngtools/webpack/src/loader.js:467:39)
at <anonymous> @ ./src/app/shared/services/lang.service.ts 14:24-62 @ ./src/app/app.module.ts @ ./src/main.ts @ multi ./src/main.ts
Run Code Online (Sandbox Code Playgroud)
我相信这是因为我npm link用来链接'sce-plugins'项目以进行本地开发.
我npm link在这里看到与Angular5项目一起使用的一些问题:
https://github.com/angular/angular-cli/issues/3875
https://github.com/angular/angular-cli/issues/8677
https://github.com/angular/angular-cli/issues/9376
有谁知道如何解决?
更新:
它似乎与npm linkperse或符号链接没有关系.如果我只是将本地目录复制到node_modules/sce-plugins,我会得到同样的错误. …
我有一个具有以下结构的打字稿nodejs服务器:
tsconfig.json
package.json
src/
middleware/
utils/
index.ts
dist/
middleware/
utils/
index.ts
Run Code Online (Sandbox Code Playgroud)
使用Typescript 2时,我可以将项目从src /转换为dist /文件夹,并可以使用我的目录结构的镜像。
随着Typescript 3的发布,他们引入了项目参考,并更改了将代码转换为输出目录的方式。现在tsc以这种嵌套方式输出到dist /文件夹:
dist/
src/
middleware/
utils/
index.ts
Run Code Online (Sandbox Code Playgroud)
我的tsconfig.json是:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"allowJs": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"resolveJsonModule": true,
"declaration": false,
"outDir": "dist/",
"lib": [
"es7",
"dom"
]
},
"include": [
"src/"
]
}
Run Code Online (Sandbox Code Playgroud)
如何配置Typescript将src /文件夹作为镜像输出到dist /文件夹中?
我正在尝试grunt在 Typescript 项目中编写一个任务来测量源文件的一些统计信息。为此,我有一个函数,它接受单个源文件,typescript.createSourceFile从中运行,并对返回的 AST 执行一些操作。问题是找到所有要迭代的文件:我想获得完全相同的文件列表,这些文件tsc -p tsconfig.json将在以后编译。目的是从该列表中过滤掉一些文件,然后遍历过滤后的列表。
我想我会使用typescript模块来做到这一点,但我找不到一个函数来做到这一点。我在tsc源代码中找到了将 tsconfig 转换为文件列表的地方,它似乎正在使用未导出的函数。
我有打字稿并使用别名。这是 tsconfig.json 的一部分
"compilerOptions": {
"baseUrl": "./src",
...
},
Run Code Online (Sandbox Code Playgroud)
通过设置基本网址,我可以改变
import User from "src/models/User.model.ts"
Run Code Online (Sandbox Code Playgroud)
到
import User from "models/User.model.ts"
Run Code Online (Sandbox Code Playgroud)
问题是 tsc 将 src 文件夹编译为 dist 文件夹,因此用户导入路径应更改为相对路径,如下所示:
"../models/User.model.js"
Run Code Online (Sandbox Code Playgroud)
但它没有改变,所以我收到以下错误:
"models/User.model.js" not found
Run Code Online (Sandbox Code Playgroud)
我搜索了答案,但没有运气。
我可以使用 JSDoc 将 TypeScript 文件转换为 JavaScript 文件吗?
例如,如果我有这个main.ts文件:
let x: string = "hello";
// This could be number or array of numbers
let y: number | number[];
Run Code Online (Sandbox Code Playgroud)
它将被转换为类似这样的main.js文件:
/**
* @type {string}
*/
let x = "hello";
/**
* This could be number or array of numbers
* @type {number | number[]}
*/
let y;
Run Code Online (Sandbox Code Playgroud)
等等。
有没有办法做到这一点?
谢谢!
我真的没有对代码进行任何更改,有一天我突然意识到这个错误,
backend: internal/modules/cjs/loader.js:454
backend: const e = new Error(`Package exports for '${basePath}' do not define a ` +
backend: ^
backend: Error: Package exports for '/Users/kumarabhirup/Documents/Repositories/propagateAt/node_modules/tslib' do not define a valid '.' target
backend: at resolveExportsTarget (internal/modules/cjs/loader.js:454:13)
backend: at resolveExports (internal/modules/cjs/loader.js:387:16)
backend: at Function.Module._findPath (internal/modules/cjs/loader.js:486:20)
backend: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:781:27)
backend: at Function.Module._load (internal/modules/cjs/loader.js:687:27)
backend: at Module.require (internal/modules/cjs/loader.js:849:19)
backend: at require (internal/modules/cjs/helpers.js:74:18)
backend: at Object.<anonymous> (/Users/kumarabhirup/Documents/Repositories/propagateAt/node_modules/apollo-link/lib/index.js:3:15)
backend: at Module._compile (internal/modules/cjs/loader.js:956:30)
backend: at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10) {
backend: code: 'MODULE_NOT_FOUND'
backend: }
backend: …Run Code Online (Sandbox Code Playgroud) tsc我对与参数一起使用的命令有一个简单的问题--build --clean,我理解该命令用于清理/擦除.js转换器(tsc)之前生成的文件。
这个命令的特殊性或者意义是什么?如果我需要删除所有文件,我可以通过目录或在目录中.js轻松完成。rm -rf *.jsdel *.js
有人可以告诉我缺失的部分吗?
在ts-toolbelt的源代码中,经常存在空对象和映射类型的交集。这样做的目的是什么?
export type ReadonlyFlat<O> = {
+readonly [K in keyof O]: O[K];
} & {}; // there
export type OptionalFlat<O> = {
[K in keyof O]?: O[K];
} & {}; // there
type __Pick<O extends object, K extends keyof O> = {
[P in K]: O[P];
} & {}; // there
Run Code Online (Sandbox Code Playgroud) tsc ×10
typescript ×10
javascript ×3
angular ×2
build ×2
node.js ×2
angular-cli ×1
angular5 ×1
commonjs ×1
jsdoc ×1
systemjs ×1
transpiler ×1
tsconfig ×1
tsdoc ×1
tslib ×1