Questions tagged «typescript-typings»

键入是管理和安装TypeScript定义的简单方法。它使用types.json,可以解析为Typings Registry,GitHub,NPM,Bower,HTTP和本地文件。

3
我如何确定@ types / *是进入`dependencies`还是`devDependencies`?
我在项目中使用TypeScript 2。我想使用一些js库,但也要使用该库的类型。我可以使用simple安装类型npm install @types/some-library。我不确定是否应该--save还是--save-dev他们。在我看来,即使DefinetelyTyped GitHub自述文件也提到了这两个版本,但从未对其进行解释。我认为@types应该在其中devDependencies,因为类型是开发所必需的,而不是在运行时使用的,但是我在just中多次看到@types dependencies。我很困惑。 我应该如何确定@ types / *是进入dependencies还是进入devDependencies?实际上有多少官方指示?

11
打字稿输入onchange event.target.value
在我的react和typescript应用程序中,我使用:onChange={(e) => data.motto = (e.target as any).value}。 我如何正确定义类的类型,这样我就不必用来绕过类型系统了any? export interface InputProps extends React.HTMLProps<Input> { ... } export class Input extends React.Component<InputProps, {}> { } 如果我把target: { value: string };我得到: ERROR in [default] /react-onsenui.d.ts:87:18 Interface 'InputProps' incorrectly extends interface 'HTMLProps<Input>'. Types of property 'target' are incompatible. Type '{ value: string; }' …

3
npm @types组织包中的TypeScript类型
我注意到有一个npm组织@types,其中包含键入包,但找不到任何文档。这些将如何使用? 它是否打算与打字工具一起使用?如果是这样,如何安装它们?例如,有一个@types/openlayers包,但是typings search npm:openlayers什么也不返回。 它是要与打字工具分开使用吗?例如直接安装npm?

8
覆盖Typescript d.ts文件中定义的接口属性类型
有没有办法改变*.d.ts打字稿中定义的接口属性的类型? 例如:中的接口x.d.ts定义为 interface A { property: number; } 我想在我写的打字稿文件中更改它 interface A { property: Object; } 甚至这将工作 interface B extends A { property: Object; } 这种方法行得通吗?当我在系统上尝试时,它不起作用。只想确认是否有可能?

4
在定义文件(* d.ts)中导入类
我想扩展Express Session类型以允许在会话存储中使用我的自定义数据。我有一个对象req.session.user,它是我的类的一个实例User: export class User { public login: string; public hashedPassword: string; constructor(login?: string, password?: string) { this.login = login || "" ; this.hashedPassword = password ? UserHelper.hashPassword(password) : ""; } } 所以我创建了我的own.d.ts文件以将定义与现有的快速会话类型合并: import { User } from "./models/user"; declare module Express { export interface Session { user: User; } …

7
属性“ X”是私有的,只能在类“ xyzComponent”中访问
我正在尝试为该博客构建用于生产的 angular2应用程序。在ngc成功编译之后,当进行tsc编译时,它将生成以下图像中所示的错误: 搜索了一会儿后,我发现这个博客在“上下文属性”部分解释了该问题,我无法正确理解该问题可能是因为它为您提供了一个很好的主意,那就是发生了什么问题。基本上,当我们将变量设为私有时,我们得到“错误:属性是私有的,并且只能在类中访问”。我不明白为什么会这样。 过去几天,我们一直在努力解决这个问题,请为我们提供帮助。

5
TypeScript 2:无类型npm模块的自定义键入
在尝试了其他地方发布的建议之后,我发现自己无法运行使用无类型NPM模块的打字稿项目。以下是一个最小的示例以及我尝试过的步骤。 对于这个最小的示例,我们将假装lodash没有现有的类型定义。因此,我们将忽略该包,@types/lodash并尝试将其类型文件手动添加lodash.d.ts到我们的项目中。 资料夹结构 node_modules Lodash src foo.ts 打字 习俗 lodash.d.ts 全球 索引 package.json tsconfig.json Types.json 接下来,文件。 文件 foo.ts ///<reference path="../typings/custom/lodash.d.ts" /> import * as lodash from 'lodash'; console.log('Weeee'); lodash.d.ts直接从原始@types/lodash包复制文件。 文件 index.d.ts /// <reference path="custom/lodash.d.ts" /> /// <reference path="globals/lodash/index.d.ts" /> 文件 package.json { "name": "ts", "version": "1.0.0", "description": "", "main": "index.js", …

4
编写自定义TypeScript定义文件时,出现错误“模块'名称'解析为...处的无类型模块”。
我找不到@type/{name}我已安装的NodeJS包之一的TypeScript定义,所以我尝试为其编写d.ts文件,然后将该文件放在{project root}\typings文件夹中。这是我的方法: // My source code: index.ts import Helper from 'node-helper-lib'; // My definition: \typings\node-helper-lib.d.ts declare....(something else) declare module 'node-helper-lib' { class Helper { ... } export = Helper; } 但是,Visual Studio Code不断产生此错误,并将红线放在下面declare module 'node-helper-lib': [ts]扩充中无效的模块名称。模块'node-helper-lib'解析为'{project path} \ node_modules \ node-helper-lib \ index.js'处的未类型化模块,无法对其进行扩充。 因为该库是无类型的,所以应该允许我在其中添加类型吗? 更新: 我在用: 打字稿:2.1.4 Visual Studio程式码:1.9.1 节点JS:6.9.4 …

1
如何为TypeScript配置自定义全局接口(.d.ts文件)?
我目前正在研究一个使用Webpack2和TypeScript的ReactJS项目。一切工作都与一件事情完全分开-我找不到一种方法来将自己编写的接口移动到单独的文件中,以使它们对整个应用程序可见。 出于原型目的,我最初在使用它们的文件中定义了接口,但最终我开始添加多个类中需要的一些接口,这就是所有问题开始的时候。无论我对我进行了什么更改tsconfig.json,无论我将文件放在哪里,IDE和Webpack都抱怨找不到名称(“找不到名称'IMyInterface'”)。 这是我当前的tsconfig.json文件: { "compilerOptions": { "baseUrl": "src", "outDir": "build/dist", "module": "commonjs", "target": "es5", "lib": [ "es6", "dom" ], "typeRoots": [ "./node_modules/@types", "./typings" ], "sourceMap": true, "allowJs": true, "jsx": "react", "moduleResolution": "node", "rootDir": "src", "forceConsistentCasingInFileNames": true, "noImplicitReturns": true, "noImplicitThis": true, "noImplicitAny": false, "strictNullChecks": true, "suppressImplicitAnyIndexErrors": true, "noUnusedLocals": true }, "exclude": …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.