我在我的脚本中遇到了来自ts.createProgram的意外输出。该函数不是从适当的文件创建单个程序对象,而是返回许多具有不同源文件属性的对象(没有一个与我期望的属性相对应)。
我的脚本是TypeScript官方维基中提供的一个示例的简化版本:
docGen.ts:
import * as ts from "typescript";
import * as fs from "fs";
function generateDocumentation(
fileNames: string[],
options: ts.CompilerOptions): void{
我想描述一些数据,比如数组中的值可以是另一个数字数组,这是无限期的,所以类型应该是递归的。
使用下面的代码,我收到一个错误
Type 'number' is not assignable to type 'Data'
type Data = ReadonlyArray<number> | Data[];
const data: Data = [1, 2, 3, [4, 5, [6, 7]]];
如何使用最新的TypeScript修复它?
我想将添加到TypeScript中的元素的scroll事件中,如下所示:
element.addEventListener("scroll", () => { }, { capture: true, passive: true });
但是TypeScript抛出一个语法错误:Argument of type '{ capture: true, passive: true }' is not assignable to parameter of type 'boolean'。
我知道错误的原因是TypeScript没有为addEventLi
在JavaScript中可以使用TypeScript库吗?
例如,我希望在中使用TypeScript,并将JS文件添加到TypeScript中并将它们添加到_references.js中。
但是,当我想在TS文件中声明时:
var r = Raphael(10,50,640,480);
Intellisense总是说:
Raphael does not exist in the current scope.
而TS文件不编译。
为什么TypeScript编译器没有将下面的情况标记为错误,有什么具体原因吗?
myFunction(len: number) {
var len: number = 5; // re-definition of local variable (name clash)
}
另一个:
myFunction() {
var b: number = a; // variable a is accessed before it is declared/initialized
var a: number = 5;
}
在将Javascript转换为TypeSc