我正在使用react-router v.2.0.0.-rc3和打字稿。我通过tsd安装了定义文件。由于他们将 mixin更改browserHistoryModule '"react-router"' has no exported member 'browserHistory'为模块,因此当通过 webpack 编译 javascript 时,我在终端上收到错误。有没有一种简单的方法可以修改react-router.d.ts文件来修复错误?或者我只需要等到他们更新定义文件?我的应用程序工作正常,只是控制台错误让我烦恼。
我正在按照Angular 2快速入门指南进行操作,并且我刚刚开始使用它.
我的公司正在过滤我们的网络连接并修改SSL协商.在中间风格的人中,他们将自签名证书指定为目的地证书的CA.
因此,当我执行第二个命令
npm install -g tsd
tsd query angular2 --action install
Run Code Online (Sandbox Code Playgroud)
我明白了:
stream.js:75
throw er; // Unhandled stream error in pipe.
^
Error: self signed certificate in certificate chain
at Error (native)
at TLSSocket.<anonymous> (_tls_wrap.js:908:38)
at emitNone (events.js:67:13)
at TLSSocket.emit (events.js:163:7)
at TLSSocket._finishInit (_tls_wrap.js:496:8)
Run Code Online (Sandbox Code Playgroud)
有人知道禁用自签名证书验证的方法吗?
我想创建一个接口,其中属性可以是a string或Function必须返回a string.我目前有以下内容:
interface IExample {
prop: string|Function;
}
Run Code Online (Sandbox Code Playgroud)
但这对我来说并不明确,因为Function它可以归还任何东西.我想告诉编译器返回值必须是a string.
这怎么可能在Typescript?或者它可能吗?
我收到了Module "ng" has no exported memberVisual Studio代码中所有输入的错误消息
我的打字是100%工作,直到我添加angular-ui-router.我不确定这是不是问题,但我在添加之后才注意到它.
在我的.d.ts文件中,我自己得到一个特定的错误angular.
我tsd.json看起来像这样
{
"version": "v4",
"repo": "borisyankov/DefinitelyTyped",
"ref": "master",
"path": "typings",
"bundle": "typings/tsd.d.ts",
"installed": {
"angular-material/angular-material.d.ts": {
"commit": "5a8fc5ee71701431e4fdbb80c506e3c13f85a9ff"
},
"jquery/jquery.d.ts": {
"commit": "40c60850ad6c8175a62d5ab48c4e016ea5b3dffe"
},
"angularjs/angular.d.ts": {
"commit": "40c60850ad6c8175a62d5ab48c4e016ea5b3dffe"
},
"angularjs/angular-route.d.ts": {
"commit": "5a8fc5ee71701431e4fdbb80c506e3c13f85a9ff"
},
"angularjs/angular-cookies.d.ts": {
"commit": "5a8fc5ee71701431e4fdbb80c506e3c13f85a9ff"
},
"angularjs/angular-animate.d.ts": {
"commit": "5a8fc5ee71701431e4fdbb80c506e3c13f85a9ff"
},
"angularjs/angular-resource.d.ts": {
"commit": "40c60850ad6c8175a62d5ab48c4e016ea5b3dffe"
},
"angular-ui-router/angular-ui-router.d.ts": {
"commit": "40c60850ad6c8175a62d5ab48c4e016ea5b3dffe"
}
}
}
Run Code Online (Sandbox Code Playgroud)
我有点迷失了我已经或者没有做过的事情.奇怪的是,一切仍然100%工作.所以我仍然得到intellsense ng.它只是说有错误,每次我建立我得到所有文件的多重错误.
更新
我结束了注释掉import ng …
我有一个用TypeScript编写的本地节点包,我想在实际项目中使用它.使用npm,我可以像这样安装本地包:
$ npm install --save /path/to/package
Run Code Online (Sandbox Code Playgroud)
要么:
$ npm install --save /path/to/package.tar.gz
Run Code Online (Sandbox Code Playgroud)
这将在node_modules目录中安装所需的.js文件.在该包中还有一个生成的.d.ts文件,我想将其安装到我的项目中(在typings/tsd.d.ts中自动链接它).但使用以下命令无效:
$ tsd install /path/to/package/package.d.ts --save
Run Code Online (Sandbox Code Playgroud)
它说>> zero results.那么,在不需要存储库的情况下安装本地定义文件的方法是什么?
更新:
我可以简单地将我的d.ts文件复制到typings目录和我的文本编辑器(对我来说,它是使用TypeScript插件的Sublime Text),它能够找到声明.目录布局是这样的:
/my-project/
/typings/
tsd.d.ts - auto-generated by `tsd install`
node/ - I've installed the node definitions
my-package.d.ts - copied or symlinked file
my-project.ts - I'm working here
Run Code Online (Sandbox Code Playgroud)
但是,在module.exports(exports = function...在TypeScript中)导出唯一的函数时,我遇到了一个问题.在这种情况下,导出的函数有点'匿名',甚至在d.ts文件中都没有命名,因此我需要手动编辑它.
我的测试用例:
'my-package'提供了一个函数,通常导入为'myPackage':
export = function myPackage(a: string, b: string) { return a + ' ' + b; };
Run Code Online (Sandbox Code Playgroud)
declarationtrue在tsconfig.json中设置为,所以该 …
在 Visual Studio Code 中,我在 tsconfig.json 的代码中有以下代码
{
"version": "1.6.0",
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"sourceMap": true,
"watch": true,
"experimentalAsyncFunctions": true,
"isolatedModules": false,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"declaration": false,
"noImplicitAny": false,
"removeComments": true,
"noLib": false,
"preserveConstEnums": true,
"suppressImplicitAnyIndexErrors": true
},
...
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,该watch选项为 true。好吧,看起来这不足以将 .ts 文件编译为 .js,就像atom-typescript 那样。基本上,保存 .ts 时,新编译的 .js 应该与 .ts 文件位于同一目录中。
另外,我想避免在我的根项目中使用 gulp,因为我已经将 gulpfile.coffee 用于其他方式。有人有线索吗?
我正在构建一个 angular2/typescript 应用程序。我看到 google 推出了platform.js,它可以访问 gapi var,如google 登录网站上所示。这很好用,但我在将它输入打字稿时遇到了很多麻烦。
TS 依赖 .d.ts 文件来导入 javascript。谷歌推出的新gapi是否有任何打字稿绑定?有这个版本的gapi来自绝对类型/gapi,但它已经过时了。
我考虑过为 google js 编写自己的类型定义,但我只能找到 google 提供的缩小版本。
如果新的 google 登录没有 tsd 绑定,我如何仍将其与打字稿一起使用?我试图将 js 文件保存到我的本地,然后执行类似的操作,
var gapi = require('../../js/lib/gapi');
但这对我不起作用,无论我如何尝试使用 javascript 导入。
尝试从旧迁移tsd.json到typings.json. 以前我.d.ts有:
declare var modname: modname.modname;
declare module modname {
export interface modname {
new (): modname;
}
export interface foo {
bar: string;
}
}
declare module "mod-name" {
export = modname;
}
Run Code Online (Sandbox Code Playgroud)
然后由于错误我将第一行更改为:
declare var modname: modname.modname;
declare namespace modname {
Run Code Online (Sandbox Code Playgroud)
但后来得到:
TS2665:模块扩充不能在顶级范围中引入新名称。
也许我应该以不同的方式安装打字?- 我注意到奇怪的脚手架被自动添加到我的定义文件中,这些文件安装有:
typings install github:user/typ/mod-name/mod-name.d.ts --save
Run Code Online (Sandbox Code Playgroud) 我正在尝试停止使用 TSD 在通过全局变量使用许多库的项目中获取类型定义(如果这很重要,outFile则使用该选项tsconfig.json)。特别是,它以这种方式使用 Moment 库。Moment 提供了自己的类型定义作为 NPM 包的一部分。但是,这些定义并未在全局范围内声明任何内容。请注意,moment这既是类型的全局变量,moment.MomentStatic又是类型命名空间。使用 NPM 包,我怎样才能扩大全局范围,使一切都开始工作,因为它现在可以使用从 TSD 获得的旧类型定义?即,moment应该在任何文件中作为变量和类型命名空间在全局范围内可用。基本上,我想要的是这样的东西:
import * as _moment from 'moment';
declare global {
const moment: _moment.MomentStatic;
import moment = _moment;
}
Run Code Online (Sandbox Code Playgroud)
这不编译:
[ts] Imports are not permitted in module augmentations. Consider moving them to the enclosing external module.
[ts] Import declaration conflicts with local declaration of 'moment'
Run Code Online (Sandbox Code Playgroud)
有解决方法吗?
我正在创建一个版本为2.0.0-alpha.46的Angular 2应用程序,我尝试导入toastr模块.
我已经下载了库,并且还下载了明确键入的文件.
在我的html页面中,我<script>为.js文件添加了一个标记:
<script src="./src/libs/toastr/toastr.min.js"></script>
Run Code Online (Sandbox Code Playgroud)
在Visual Studio Code中,我尝试导入模块,如下所示:
import * as toastr from 'toastr';
Run Code Online (Sandbox Code Playgroud)
然后我可以在我的组件中调用toastr.info('message') - 我甚至可以获得intellisense; 但是,当我实际尝试加载网页时,我得到404/src/toastr not found错误.
如果我试图明确找到toastr明确键入的文件:
import * as toastr from '../../definitions/toastr/toastr';
Run Code Online (Sandbox Code Playgroud)
我会得到"[ts模块的完整路径]不是一个模块."
我也尝试添加///<reference path="../../toastr.d.ts" />到我用来导入模块的文件的顶部无济于事.
有没有人知道可能会发生什么?我对我可能出错的事情画了一个空白.提前致谢.
这是一个路障。我究竟做错了什么?
....
/// <reference path="../../../typings/tsd.d.ts" />
var slider:HTMLElement = document.getElementById('slider');
noUiSlider.create(slider, {
start: +$input.val(),
step: +$input.prop('step'),
behaviour: 'tap',
range: {
'min': +$input.prop('min'),
'max': +$input.prop('max')
},
format: wNumb({
decimals: 0,
thousand: ','
})
});
// this barfs in TS — error in as title of this post
slider.noUiSlider.on('update', (values, handle) => {
$input.val(values[0]);
});
// this does too.
<HTMLElement>slider.noUiSlider.on('update', (values, handle) => {
$input.val(values[0]);
});
Run Code Online (Sandbox Code Playgroud)
我的TSD文件包含从https://github.com/retyped/nouislider-tsd-ambient/blob/master/nouislider.d.ts输入的nouislider。
错误详情:
{ [TypeScript error: resources/assets/typescript/common.ts(44,25): Error TS2339: Property 'noUiSlider' does not exist on …Run Code Online (Sandbox Code Playgroud) tsd ×11
typescript ×10
angular ×2
tsc ×2
browserify ×1
declaration ×1
google-oauth ×1
momentjs ×1
npm ×1
react-router ×1
reactjs ×1
ssl ×1
syntax ×1
task ×1
toastr ×1
webpack ×1