我很难让我的项目用已安装的类型进行编译。我正在使用MediaRecorder,我已经安装了@types/dom-mediacapture-record。使用默认设置,我无法识别MediaRecorder。
我已经设法让事情工作1)不扩展@tsconfig/svelte/tsconfig。2)添加特定类型以及"svelte"在types下:"types" ["sevlte", "@types/dom- medicapture -record"]我无法使用typeRoots
使其工作我在网上找不到其他人有这个问题的例子,所以我觉得我一定错过了一些明显的东西。
这是我很快尝试过的,似乎有效(不需要对tsconfig.json
进行任何更改):
编辑
我发现除了dom-mediacapture-record
外,从当前项目导入某些类型(而不是从node_modules
导入一些类型)时,我的原始代码存在问题。在declare global {...}
中包装interface Window...
解决了这个问题。下面是更新后的代码:
// add a file "<your filename here>.d.ts" to your src directory containing
// the following code:
// import the types from @types/dom-mediacapture-record in order
// to extend the existing Window type with them
import * as dmr from "dom-mediacapture-record";
import type { MyCustomInterface } from "./customStuff";
// Using TypeScript's declaration merging, "extend" the existing
// Window interface
declare global {
interface Window extends dmr, MyCustomInterface {}
}
编辑前版本:
// add a file "<your filename here>.d.ts" to your src directory containing
// the following code:
// import the types from @types/dom-mediacapture-record in order
// to extend the existing Window type with them
import * as dmr from "dom-mediacapture-record";
// Using TypeScript's declaration merging, "extend" the existing
// Window interface
interface Window extends dmr {}