Tag: 打字稿

如何在输出目录中使用TypeScript包含node_modules

我想知道是否可以在运行tsc命令后将node_modules文件夹复制到输出目录中。 我的情况是,我有一个与TypeScript的项目,并使用一些NPM包。 我需要我的输出目录具有所有的npm依赖关系,因为我需要压缩它并通过http发送(到AWS Lambda)。 我的项目结构是这样的: |-.vscode –> visual studio code |-lib –> output dir |-node_modules –> npm dependencies |-src –> .ts files |-jsconfig.json |-tsconfig.json 怎么能实现呢? 非常感谢!

如何在Node.js中注册全局的TypeScript Enum

我想使我的TypeScript枚举全局,所以我不需要跨我的应用程序导入它们。 我到目前为止: 读state.enum.ts export enum ReadState { Unread = 4000, Read = 4001 } enums.ts import { ReadState } from './read-state.enum'; const enums = { ReadState } global['Enums'] = enums; declare var Enums: typeof enums; 然后在index.ts中 import './enums'; // do this once to initialize enums var _enums = Enums; // [ts] Cannot find name 'Enums'. […]

使用Typescript的持久性

我目前正在使用Electron(基本上是带有铬的nodejs)加上Angular2 有没有办法在文件中保存打字稿对象? 目前,我将对象保存在json文件中。 问题是所有的对象方法都丢失了 我应该尝试保存__proto__variables吗? 我应该使用框架还是特殊的数据库引擎? 今天我从json文件中读取对象并使用JSON.parseparsing它。 然后我重新分配一个新的对象的所有属性,这是不可扩展的 任何build议是值得欢迎的 提前致谢。 何塞

打字稿。 不在特定的机器上编译

我有一个很小的项目,在我的家用机器上完美编译,但是我在另一台PC上收到了数百个错误。 我可以注意到的环境唯一的区别是,我有麻烦的PC是在Windows 8下(PC上的Windows 10和Ubuntu的工作正常)。 全球npm列表(深度= 0): +– npm@4.1.1 +– typescript@2.1.5 `– typings@2.1.0 tsc version = 1.0.3.0 tsconfig.json : { "compilerOptions": { "module": "commonjs", "noImplicitAny": false }, "exclude": [ "node_modules" ] } 问题以/// <reference path="node_modules/@types/jquery/index.d.ts" /> 这就是我的输出如下所示:

导出variables“路由器”具有或正在使用来自外部模块的名称“路由器”,但无法命名

在直接使用Typescript 2和@types/express@4.0.35定义导出路由器时,在多个文件中定义嵌套路由器的常见结构如下代码抛出 error TS4023: Exported variable 'router' has or is using name 'Router' from external module "[…]/node_modules/@types/express-serve-static-core/index" but cannot be named. 从basarat的答案采取的例子 import * as express from "express"; // import sub-routers import * as adminRouter from "./admin/admin"; import * as productRouter from "./products/products"; let router = express.Router(); // mount express paths, any addition middleware can […]

@ types / node和VS代码:因为注释格式化,IntelliSense不起作用

我使用的Visual Studio代码和@ types /节点(7.0.8),但似乎有些function等有一个错误的格式化的代码注释,因此Visual Studio代码和Visual Studio 2017不会显示任何在IntelliSense中的quickinfos。 例 import * as fs from 'fs'; fs.unlink 当我inputfs.unlink VS Code显示函数签名,但不是定义的注释 ./node_modules/@types/node/index.d.ts 在线2400 /* * Asynchronous unlink – deletes the file specified in {path} * * @param path * @param callback No arguments other than a possible exception are given to the completion callback. */ export function unlink(path: […]

在webpack编译的JavaScript中读取NodeJS的process.argv

我试图用webpack编译一个简单的TS文件(通过“awesome-typecript-loader”),它应该读取命令行参数。 不过,我相信编译后的JS正在用一个闭包制作过程来重新定义Node的'process'variables.argv'undefined'。 TL; DR :如何用webpack编译的JS读取命令行参数? a.ts console.log(process.argv[2]); webpack.config.js const path = require('path'); module.exports = { resolve:{ extensions: ['.ts'] }, module: { rules: [{ test: /\.ts$/, loaders: ['awesome-typescript-loader'], include: [ path.resolve(__dirname, "src") ] }] }, entry: { a: "./src/a.ts" }, output: { path: path.resolve(__dirname, 'output'), filename: '[name].js' } }; 的package.json { "name": "my-proj", "version": "1.0.0", "description": […]

使用node-sqlite将数据从一个数据库复制到另一个数据库 – 格式化“插入”语句

我正在写一个小的实用程序将数据从一个sqlite数据库文件复制到另一个。 两个文件都有相同的表结构 – 这完全是关于从一个数据库移动到另一个数据库的行。 我的代码现在: let tables: Array<string> = [ "OneTable", "AnotherTable", "DataStoredHere", "Video" ] tables.forEach((table) => { console.log(`Copying ${table} table`); sourceDB.each(`select * from ${table}`, (error, row) => { console.log(row); destDB.run(`insert into ${table} values (?)`, …row) // this is the problem }) }) 这里的row是一个js对象,每个表都有键控数据。 我敢肯定,有一个简单的方法来做到这一点,不涉及转义string数据。

打字稿:按价值或参考传递

我有这个文件: object.ts: export const myObject { prop1: "prop1", prop2: "prop2", … … } 我有这个class 我-class.ts export class MyClass { private obj: any; constructor(obj: any) { this.obj = obj } } 我有这个文件: main.ts import { myObject } from "object"; import { MyClass } from "my-class"; let class1 = new MyClass(myObject); let class2 = new MyClass(myObject); let […]

在angular2组件中需要节点模块

我不知道如何在我的angular2组件中需要节点模块 – 特别是在我的情况下,如何在angular2组件中打开一个新的电子窗口。 我的component.html有这样的东西 <button class="btn btn-success" (click)="buttonLoginClick()">Login</button> 在component.ts中,我使用以下内容 export class LoginComponent { constructor() {} buttonLoginClick(): void { alert("just a test"); const remote = require('electron').remote; const BrowserWindow = remote.BrowserWindow; var win = new BrowserWindow({ width: 800, height: 600 }); win.loadURL('./test.html'); } } 编译错误在说 找不到名字'require'。