【发布时间】:2021-11-30 22:43:42
【问题描述】:
以下代码来自 Deno Chalk 库的 README。 Deno/Typescript 不会让它通过:
import chalk from "https://deno.land/x/chalk_deno@v4.1.1-deno/source/index.js";
// Run this in debugger and it's fine but it won't compile:
console.log(chalk.blue("Hello world!"));
console.log(eval("typeof chalk.blue"), "At runtime it's fine!");
输出:
错误:TS2339 [错误]:类型 '{ (...arguments_: any[]): string; 上不存在属性 'blue'粉笔:粉笔类型; }'。 console.log(chalk.blue("Hello world!"));
已修补:
注释掉第 3 行,它运行良好!那么chalk.blue 在运行时可用但对编译器不可见??
function 在运行时就可以了!
【问题讨论】:
标签: typescript deno chalk