Tag: 打字稿

Guid类在node.js中

我使用Node作为后端,我正在寻找一个可以为我生成Guid的类。 我遇到了https://www.npmjs.com/package/guid 我安装它作为npm安装guid。 但是,我不确定如何在我实际使用它之前将其导入到我的课堂中。

使用asynchronous和等待减less

我知道,其他文章涵盖了这个问题,但我需要使用它作为const所以它只是在运行时初始化 这是我的问题,我是nodejs的新手,并在网上search了很多。 没有find任何解决scheme接近我的需要 const apis = ['log', 'get', 'all'] const loggers = apis.reduce(async (memo, api) => { try { await fs.stat(path.join(process.cwd() + config.application.log.dir, api)); } catch (e) { await fs.mkdir(path.join(process.cwd() + config.application.log.dir, api)); } memo[api] = new (winston.Logger)({ transports: [ new winston.transports.File({ timestamp: () => (new Date().toLocaleTimeString()), datePattern: 'yyyy-MM-dd', level: config.application.mode === 'test' ? 'emerg' […]

无限的Webpack手表循环 – 如何忽略.js文件的变化等

我使用ts-loader的webpack -w命令处于无限循环状态。 我猜测这是因为webpack -w正在看到.js文件的变化,所以导致循环 : webpack -w => ts transpile => .js changes => webpack -w 有没有人见过这个? 告诉webpack-w忽略.js文件是最好的办法吗? 我怎样才能做到这一点? 这是我的webpack.config.js文件: module.exports = { entry: ['babel-polyfill', './lib/index.ts'], output: { path: path.resolve(__dirname + '/dist'), filename: 'suman.js' }, module: { rules: [ // all files with a `.ts` or `.tsx` extension will be handled by `ts-loader` { test: […]

npm install –save-dev @ ts2.0无效的标签名称“@ ts2.0”

所以当我input: npm install @ts2.0 –save-dev 我有这个错误: npm ERR! 代码EINVALIDTAGNAME npm ERR! 无效的标签名称“@ ts2.0”:标签可能没有任何encodeURIComponent编码的字符。 任何想法为什么? 问候和感谢

创buildPowerBI的自定义视觉时,无法在NodeJS中使用MomentJS

我正在为Power BI构build一个定制视觉,但我不确定这是否与我的问题更一般的问题有关。 无论如何,自定义视觉是使用Node.js和typescript构build的,使用自定义库应该没有问题( 链接 )。 但是,当我添加了一些时候,当我尝试使用它时,我的脚本就会“挂起”。 我没有收到错误消息或exception或其他。 使用下面的行 console.log('Trying moment.js'); console.log(moment); console.log('Moment-testing success'); 输出Trying moment.js后“停止”。 这些是我已经采取安装momentjs的步骤: 冉npm install momentjs –save 在我的tsconfig.json files中添加了"node_modules/moment/moment.d.ts" 。 根据我的理解,moment.d.ts是一个“header”文件,它只在我的IDE中用于autocompelte / InteliJ,即它只包含函数的声明,而不包含定义。 只要我添加这一行,我的IDE停止抱怨找不到moment 。 在externalJS ( link )下面添加"node_modules/moment/moment.js"给我的pbiviz.json 在package.json dependencies下添加"moment": "^2.19.1", 。 有什么我错过了吗? 这感觉就像我的应用程序无法find实际的moment .js并解决什么moment是…

打字稿错误中的string枚举

我试图添加一个string枚举到我的Angular 2项目,但是在使用npm开始项目期间发生错误: ERROR in e:/projects/dbtool-fullstack/dbtool-client/src/app/shared/models/full-m odels/enums/Sex.ts (2,10): Type '"Male"' is not assignable to type 'Sex'. ERROR in e:/projects/dbtool-fullstack/dbtool-client/src/app/shared/models/full-m odels/enums/Sex.ts (3,12): Type '"Female"' is not assignable to type 'Sex'. ERROR in e:/projects/dbtool-fullstack/dbtool-client/src/app/shared/models/full-m odels/enums/Sex.ts (4,8): Type '"NA"' is not assignable to type 'Sex'. 枚举声明: export enum Sex { Male = 'Male', Female = 'Female', NA = 'NA' […]

导入到Node.js的TypeScript文件没有被名称空间部分声明识别的包?

我正在使用JetBrain的WebStorm IDE来编辑TypeScript文件作为Node.js v8.6.0项目的一部分。 我的项目的JavaScript版本设置为JSX Harmony 。 TypeScript源文件的顶部是一个导入语句,用于将包别名到标签签名者 : import {Signer as signer} from '../lib/rds/signer'; 但是,WebStorm的语法荧光笔将导入标记为未使用 。 尽pipe事实上这个别名是在下面的命名空间部分中使用的,后来在相同的TypeScript文件中: declare namespace RDS { export import Signer = signer; } 更糟糕的是, 导出导入行被标记为错误,表明签名者被认为是未解决的符号 。 如何解决此问题,以便WebStorm将签名者识别为导出导入声明的有效值,并且随后导致Signer软件包导入不被使用?

将Firestore依赖项和types导入到node.js

我最近在今年的FirebaseSummit会谈后将我的云function更新到了TypeScript 。 我所有的代码看起来相当酷,但我有一些问题,试图恢复types的Firestore API,如QuerySnapshot , DocumentReference … async function getEventsMadeByUser(userId: string): Promise<FirebaseFirestore.DocumentSnapshot[]> { const eventsMadeByUserQuery = await instance.collection('PrivateUserData') .doc(userId).collection(EVENTS) .where('interactionUser', '==', userId).get(); return eventsMadeByUserQuery.docs; } 现在我的IDE(WebStorm)没有获取FirebaseFirestore的types。 这是我的package.json外观: { "name": "functions", "description": "Cloud Functions for Firebase", "dependencies": { "firebase-admin": "^5.4.3", "firebase-functions": "^0.7.2" }, "devDependencies": { "@types/express": "^4.0.37", "typescript": "^2.3.2" }, "scripts": { "build": "tsc", "watch": "tsc […]

导入的打字稿对象不具有该属性

我用Typescript使用nodeJs: 这是我在dbconfig.ts中的 interface DatabaseConfig { username: string; password: string; database: string; host: string; dialect: string; port?: number; logging?: boolean | Function; force?: boolean; timezone?: string; } interface DatabaseConfigs { development: DatabaseConfig, staging: DatabaseConfig, production: DatabaseConfig } var configs: DatabaseConfigs = { development: { username: "postgres", password: "password", database: "development", host: "localhost", dialect: "postgres" }, staging: […]

如何在angular度2项目中使用“regression-js”

我在我的Angular 2应用程序中导入回归npm模块https://www.npmjs.com/package/regression以使用线性回归函数。 我使用"npm install regression"安装软件包。 现在我已经尝试了几个使用该软件包的东西: 我试过的第一件事: import regression from 'regression'; const result= regression.linear([0, 1], [32, 67], [12, 79]); // this line is giving error, — can not use linear on undefined. 第二件事我已经试过了: import {Regression} from "regression"; regresiionvar: Regression; const result= this.regresiionvar.linear([0, 1], [32, 67], [12, 79]); // but still undefined error. 我试过的第三件事: import {Regression} […]