Questions tagged «definitelytyped»

22
TypeScript出现错误TS2304:找不到名称“ require”
我正在尝试启动并运行我的第一个TypeScript和DefinitelyTyped Node.js应用程序,并且遇到一些错误。 当我尝试转换一个简单的TypeScript Node.js页面时,出现错误“ TS2304:找不到名称'require'”。我已经阅读了Stack Overflow上此错误的其他几种情况,但我认为我没有类似的问题。我在shell提示符下运行命令: tsc movie.server.model.ts. 该文件的内容是: 'use strict'; /// <reference path="typings/tsd.d.ts" /> /* movie.server.model.ts - definition of movie schema */ var mongoose = require('mongoose'), Schema = mongoose.Schema; var foo = 'test'; 错误被抛出var mongoose=require('mongoose')行。 Types / tsd.d.ts文件的内容是: /// <reference path="node/node.d.ts" /> /// <reference path="requirejs/require.d.ts" /> .d.ts文件引用放置在适当的文件夹中,并通过以下命令添加到Types / tsd.d.ts中: …

2
有没有一种方法可以“提取” TypeScript接口属性的类型?
假设有一个库X的键入文件,其中包含一些接口。 interface I1 { x: any; } interface I2 { y: { a: I1, b: I1, c: I1 } z: any } 为了使用该库,我需要传递与类型完全相同的对象I2.y。我当然可以在源文件中创建相同的界面: interface MyInterface { a: I1, b: I1, c: I1 } let myVar: MyInterface; 但是我却要负担使其与库中的库保持最新的负担,而且它可能很大,并导致大量代码重复。 因此,是否有任何方法可以“提取”该接口的特定属性的类型?类似的内容let myVar: typeof I2.y(不起作用,并导致“找不到名称I2”错误)。提前致谢。 编辑:在TS游乐场玩了一点之后,我注意到以下代码完全实现了我想要的功能: declare var x: I2; let y: typeof x.y; …
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.