因此,基本上,我想使用TypeScript来检查我的代码在编辑器中是否有错误(VS代码),但不想执行任何转换步骤。
我在.js文件中有我的代码,"allowJs":tsconfig.json中的真
唯一的问题是,编辑器会抱怨js文件中的类型记录词的使用,例如:
declare module "something" {
export interface MyInterface {
导致错误:
"'module' declarations can only be used in TypeScript files"
我试图不去
在我的Angular类(Typescript)中,我有一个构造函数:
constructor(public http: Http) {
[...]
}
这是jsDoc注释此构造函数的参数的正确方式吗?
/**
* @constructor
* @param {Http} Http service
* called when the ApiService is created
*/
/**
* @param {Object[]} items - Payload should be an array or objects which includes name property
* @return {String[]} Returns names of all objects in that array
*
*/
const namesOfItems = (items) => {
return items.map((item) => item.name)
} 我有这样的代码。它接受一个名为items的参数。Items应该是任何对象数组,如user
如何使用JSDoc注释向TypeScript编译器声明“类型X具有Y类型的所有属性,以及这些其他属性”?
给予:
/**
A base type with one property.
@typedef {object} Base
@prop {string} name
*/
/**
A subtype that adds a second property.
@typedef AugmentedBase
@type {Base}
@prop {number} age
*/
/**
A function declared to return AugmentedBase, so name
我为我的应用程序conf.ts提供了一个配置文件,它将其他文件中的配置值合并起来,以保持它的组织性。我合并它们,因为当我想要使用一个配置值时,编写Conf.MY_LONG_NAMED_VALUE比编写Conf.SubCategory.MY_LONG_NAMED_VALUE更容易。
import {CoreConf} from './conf/game/core.conf';
import {ViewConf} from './conf/view/view.conf';
import {DebugConf} from './conf/game/debug.
在放弃之前,我想在这里试一试。 我有一个定义文件,其类型如下: /**
* My json decode function, in reality very different
* implementation (class like) but it works as an example
*/
function decodeJSON<T = unknown>(str: string): T; 如果我想在TypeScript中使用这个泛型,我会做如下操作 const value = decodeJSON<number[]>("[1,2,3]"
我使用for作为我的打字代码。我想记录一个接口的属性。tsLint给出了一个错误JSDoc tag '@property' is redundant in TypeScript code. (no-redundant-jsdoc)tslint(1)
以下是我的评论
/**
* @property value - number with a unit as string
*/
禁用下一行的tslint也不起作用。
我想知道如何在JSDoc 11中正确地使用WebStorm 11标记node.js应用程序中的类和类型以获得代码完成等。
示例:
A档案:
function A(){
this.b = true;
}
A.prototype.doSth = function doSth() {
return !this.b;
}
module.export = new A();
档案B:
var foo = bar(); // returns type of A
现在我想要“foo”的代码完成,因此它建议foo.b、foo.doSth、.
我尝试了很多JSDoc条目,比如@class、@构造
在我的globals.d.ts中,我导出了多个函数,这些函数的参数也是函数。下面是一个示例:
/**
* Does something
* @param {function(string): void} bar - a parameter
* @returns {void}
*/
export function foo(bar: function(string): void): void;
ESLint显示多个错误,声明:JSDoc types can only be used inside documentation comments.。我尝试通过从函数中删除类型并仅在注释中声明它们
目标是从TypeScript代码中获取JSDoc文档。来自TypeDoc (TypeScript文档解决方案)的文档的质量是不可接受的,因为文档是针对JS用户的,不应该被特定于TypeScript实现(接口等)的细节所淹没。
目前,转换为ES6并从JS文件生成文档在很大程度上做到了这一点。没有赋值的属性除外。就像看起来的那样,
class A {
/**
* @private
* @var _a
*/
private _a;
/**
* @public
* @var a
*/
public a = t