Tag: tsc

tsc生成.d.ts文件给出错误“找不到命名空间”Jimp“

我正在开发一个NPM包,我的一个类是这样的: import { MIME_PNG } from 'jimp'; import { IDimensions } from './spritesheet'; /** * A class for a single sprite. This contains the image * and supporting data and methods */ export class Sprite { image: Jimp.Jimp; dimensions: IDimensions; /** * * @param img a jimp image of the sprite */ constructor (img: Jimp.Jimp) […]

打字稿冲突的variables名称

我试图编译一些Node.js打字稿的代码,但我遇到了两个名为consolevariables的问题。 本质上,Node.js有一个console.trace()方法,而正常的浏览器端JavaScript不。 我在我的Typescript文件中引用了node.d.ts,其他一切正常。 node.d.ts将console声明为一个variables,但是lib.d.ts也是如此,这似乎是在重写Node.js版本。 将–nolib添加到编译器只会引发数百个关于未定义符号的错误。 有没有办法解决这个问题,而不编辑lib.d.ts? (或者控制台: (<any>console).trace() ?)

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

我有一个很小的项目,在我的家用机器上完美编译,但是我在另一台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" /> 这就是我的输出如下所示:

获取错误:如何从打字稿中正确使用我的转录和打字的打字稿npm模块?

我仍然打字打字。 我写了一个简单的“hello world”打字稿模块,并将其发布到npm 。 真的很平凡,只是做一个默认导出: export default function hello(target: string = 'World'): void { console.log(`Hello, ${target} :-(`) } 它被node.js 0.10 – > 6消耗得非常好。该模块在package.json中也具有适当的"typings"属性,指向由tsc生成的现有的.d.ts文件, 正如在官方文档中所解释的 : export default function hello(target?: string): void; 但是,打字稿1.8和2都不能打印它, import hello = require('hello-world-emo') hello() hello('Offirmo') 使用tsc传输或使用ts-node执行都会给出相同的错误消息: TSError: ⨯ Unable to compile TypeScript hello.ts (3,1): Cannot invoke an expression whose type lacks a […]

如何让TypeScript编译器不发出目录结构

在我当前的TypeScript项目中,我有以下文件结构: project ├─app │ └─index.html ├─test └─src ├─app │ ├─tsconfig.json │ └─app.ts ├─lib │ └─lib.ts └─test ├─tsconfig.json └─test.ts 我想实现的是,当编译这个项目的app并test生成的文件结构如下所示: project ├─app │ ├─index.html │ └─app.js ├─test │ ├─lib │ │ └─lib.js │ └─test.js └─src └─… 或这个: project ├─app │ ├─index.html │ └─app.js ├─test │ ├─lib.js │ └─test.js └─src └─… 我有一个库位于lib目录中。 它被app.ts使用,然后在网页上使用。 testing位于testing目录内。 我实际得到的是: project ├─app […]

Typescript – tsc编译器会中断我的代码

我在Typescript中编写了这个代码 import redis from 'redis'; import Promise from 'bluebird'; const DEFAULT_REDIS_TTL = 7200; // 2 hours export default class Redis { readonly client : any; ttl : number = DEFAULT_REDIS_TTL; constructor(uri? : string, ttl : number = DEFAULT_REDIS_TTL) { this.client = redis.createClient(uri); } … } export { Redis }; 编译器给了我这个 "use strict"; Object.defineProperty(exports, "__esModule", { […]

无法在OS X中通过terminal安装tsc

我试图安装tsc,但是当我运行它时,我得到大量的错误。 我已经尝试重新安装节点和npm现在至less三次,但无济于事。 我设置标志为我的NPM详细,这是我得到的: Mitch:~ mitch$ npm install -g typescript npm info it worked if it ends with ok npm verb cli [ '/usr/local/bin/node', npm verb cli '/usr/local/bin/npm', npm verb cli 'install', npm verb cli '-g', npm verb cli 'typescript' ] npm info using npm@2.11.3 npm info using node@v0.12.7 npm verb install initial load of /usr/local/lib/package.json […]

在使用npm定义时,tsc如何得到它的定义

所以我从使用typings到使用npm 。 因此,您在@types中有@types目录,但除此之外,没有其他文件。 随着typings我总是不得不包括index.d.ts文件index.d.ts ,但使用npm这是没有必要的。 我想问一下为什么是这样。 npm是否使用了tsc某种隐藏function,或者微软和npm背后的人是否同意?

TSC错误TS1110 node.d.ts Node.js v6.x

运行tsc我得到了很多的表单错误 typings/node/node.d.ts(Ln,Col): error TS1110: Type expected. 供参考: node.d.ts的第一行说 //为Node.js v6.x定义types 这些错误的原因是什么以及如何解决这些错误? 重现步骤:在只有文件tsconfig.json的目录中 { "compilerOptions": { "target": "es5", "sourceMap": true, "module": "commonjs", "outDir": "." } } 接下来,执行命令tsd install body-parser –save ,output: – body-parser / body-parser -> express > express -> serve-static > serve-static -> express-serve-static-core > express-serve-static-core -> node > node -> mime > mime > […]

TypeScript – 使用<reference path =“…”>标记

我想添加一个插件到TypeScript编译器,所以我添加了我的代码,我编译了tsc.ts. 它编译正确,但是当我运行时,它缺less一些在io.ts中声明的variables。 我删除了我的更改,但仍然无效。 所以我试过这个: 文件:a.ts var a : number = 5; 文件:b.ts ///<reference path='a.ts' /> console.log(a); 然后编译: tsc b.ts给我a.js和b.js. 当我尝试运行b.js(我做node b.js )时,variablesa是未定义的。 这是b.js的内容: ///<reference path='a.ts' /> console.log(a); 所以a是不确定的,因为a在这个文件中是不存在的,所以a.ts 。 我编译错了,还是执行错了..或者是什么?