我刚刚从Typescript 4.2.4升级到Typescript 4.8.4,现在遇到错误,因为node_modules/Typescript/lib/lib.dom.d.ts中的类型与";铬";在tsconfig文件的types条目中键入。
错误为:
node_modules/@types/filesystem/index.d.ts:107:5 - error TS2687: All declarations of 'name' must have identical modifiers.
107 name: string;
~~~~
node_modules/@types/filesystem/index.d.ts:113:5 - error TS2687: All declarations of 'root' must have identical modifiers.
113 root: DirectoryEntry;
~~~~
node_modules/@types/filesystem/index.d.ts:113:5 - error TS2717: Subsequent property declarations must have the same type. Property 'root' must be of type 'FileSystemDirectoryEntry', but here has type 'DirectoryEntry'.
113 root: DirectoryEntry;
~~~~
node_modules/typescript/lib/lib.dom.d.ts:5248:14
5248 readonly root: FileSystemDirectoryEntry;
~~~~
'root' was also declared here.
node_modules/@types/filesystem/index.d.ts:369:11 - error TS2304: Cannot find name 'DOMError'.
369 (err: DOMError): void;
~~~~~~~~
node_modules/typescript/lib/lib.dom.d.ts:5247:14 - error TS2687: All declarations of 'name' must have identical modifiers.
5247 readonly name: string;
~~~~
node_modules/typescript/lib/lib.dom.d.ts:5248:14 - error TS2687: All declarations of 'root' must have identical modifiers.
除了缺失的";DomError";出现错误是因为FileSystem在两个声明文件中的声明不同。
filesystem.index.d.ts有一个名为filesystem 的接口
interface FileSystem {
/**
* This is the name of the file system. The specifics of naming filesystems is unspecified, but a name must be unique across the list of exposed file systems.
* @readonly
*/
name: string;
/**
* The root directory of the file system.
* @readonly
*/
root: DirectoryEntry;
}
lib/lib.dom.d.ts还有一个名为FileSystem的接口,如下所示:
interface FileSystem {
readonly name: string;
readonly root: FileSystemDirectoryEntry;
}
我该如何解决这个问题?
FileSystem
类型自4.4起嵌入dom.d.ts
。
您不再需要@types/filesystem
。
升级到最新的@types/filesystem解决了这个问题。
看看这个答案:https://stackoverflow.com/a/45744513/12800045
它说你可以跳过编译器选项中的类型检查库