Skip to content

vue-tsc 使用 --skipLibCheck 编译选项仍然会检查 node_module 目录中qiniu-js导致检查通过 #619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
junjiantech opened this issue Jan 27, 2023 · 5 comments

Comments

@junjiantech
Copy link

在使用 七牛云 对象存储SDK时引入官方 JavaScript V3 的依赖 qiniu-js 运行 vue-tsc 检查时发现很多问题. 通过查询文档得知可以增加 --skipLibCheck 参数解决三方库的检查问题,但增加参数后发现并无法正常工作。

项目使用的依赖情况
vue-tsc: ^0.38.4
vite: ^3.0.0
typescript: ^4.6.4
qiniu-js: ^3.4.1

执行如下命令

vue-tsc --noEmit --skipLibCheck

输出

macbox:Roubin (develop) $ vue-tsc --noEmit --isolatedModules
node_modules/qiniu-js/src/api/index.ts:84:20 - error TS7053: Element implicitly has an 'any' type because expression of type '"Content-MD5"' can't be used to index type '{ Authorization: string; 'content-type': string; }'.
  Property 'Content-MD5' does not exist on type '{ Authorization: string; 'content-type': string; }'.

84   if (options.md5) headers['Content-MD5'] = options.md5
                      ~~~~~~~~~~~~~~~~~~~~~~

node_modules/qiniu-js/src/upload/base.ts:117:13 - error TS2564: Property 'assessKey' has no initializer and is not definitely assigned in the constructor.

117   protected assessKey: string
                ~~~~~~~~~

node_modules/qiniu-js/src/upload/base.ts:118:13 - error TS2564: Property 'bucketName' has no initializer and is not definitely assigned in the constructor.

118   protected bucketName: string
                ~~~~~~~~~~

node_modules/qiniu-js/src/upload/base.ts:120:13 - error TS2564: Property 'uploadAt' has no initializer and is not definitely assigned in the constructor.

120   protected uploadAt: number
                ~~~~~~~~

node_modules/qiniu-js/src/upload/base.ts:121:13 - error TS2564: Property 'progress' has no initializer and is not definitely assigned in the constructor.

121   protected progress: UploadProgress
                ~~~~~~~~

node_modules/qiniu-js/src/upload/base.ts:164:20 - error TS2345: Argument of type 'unknown' is not assignable to parameter of type 'QiniuError'.

164       this.onError(error)
                       ~~~~~

node_modules/qiniu-js/src/upload/base.ts:295:20 - error TS2345: Argument of type 'unknown' is not assignable to parameter of type 'QiniuError'.

295       this.onError(err)
                       ~~~

node_modules/qiniu-js/src/upload/resume.ts:45:11 - error TS2564: Property 'chunks' has no initializer and is not definitely assigned in the constructor.

45   private chunks: Blob[]
             ~~~~~~

node_modules/qiniu-js/src/upload/resume.ts:50:11 - error TS2564: Property 'usedCacheList' has no initializer and is not definitely assigned in the constructor.

50   private usedCacheList: boolean[]
             ~~~~~~~~~~~~~

node_modules/qiniu-js/src/upload/resume.ts:55:11 - error TS2564: Property 'cachedUploadedList' has no initializer and is not definitely assigned in the constructor.

55   private cachedUploadedList: UploadedChunkStorage[]
             ~~~~~~~~~~~~~~~~~~

node_modules/qiniu-js/src/upload/resume.ts:60:11 - error TS2564: Property 'uploadedList' has no initializer and is not definitely assigned in the constructor.

60   private uploadedList: UploadedChunkStorage[]
             ~~~~~~~~~~~~

node_modules/qiniu-js/src/upload/resume.ts:65:11 - error TS2564: Property 'loaded' has no initializer and is not definitely assigned in the constructor.

65   private loaded: ChunkLoaded
             ~~~~~~

node_modules/qiniu-js/src/upload/resume.ts:70:11 - error TS2564: Property 'uploadId' has no initializer and is not definitely assigned in the constructor.

70   private uploadId: string
             ~~~~~~~~

node_modules/qiniu-js/src/utils/compress.ts:32:61 - error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ readonly PNG: "image/png"; readonly JPEG: "image/jpeg"; readonly WEBP: "image/webp"; readonly BMP: "image/bmp"; }'.
  No index signature with a parameter of type 'string' was found on type '{ readonly PNG: "image/png"; readonly JPEG: "image/jpeg"; readonly WEBP: "image/webp"; readonly BMP: "image/bmp"; }'.

32 const supportMimeTypes = Object.keys(mimeTypes).map(type => mimeTypes[type])
                                                               ~~~~~~~~~~~~~~~

node_modules/qiniu-js/src/utils/compress.ts:42:11 - error TS2564: Property 'outputType' has no initializer and is not definitely assigned in the constructor.

42   private outputType: string
             ~~~~~~~~~~

node_modules/qiniu-js/src/utils/helper.ts:1:22 - error TS7016: Could not find a declaration file for module 'spark-md5'. '/Users/lumo/Projects/typescripts/Roubin/node_modules/spark-md5/spark-md5.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/spark-md5` if it exists or add a new declaration (.d.ts) file containing `declare module 'spark-md5';`

1 import SparkMD5 from 'spark-md5'
                       ~~~~~~~~~~~

node_modules/qiniu-js/src/utils/helper.ts:132:14 - error TS2339: Property 'ActiveXObject' does not exist on type 'Window & typeof globalThis'.

132   if (window.ActiveXObject) {
                 ~~~~~~~~~~~~~

node_modules/qiniu-js/src/utils/helper.ts:133:23 - error TS2339: Property 'ActiveXObject' does not exist on type 'Window & typeof globalThis'.

133     return new window.ActiveXObject('Microsoft.XMLHTTP')
                          ~~~~~~~~~~~~~

node_modules/qiniu-js/src/utils/helper.ts:259:14 - error TS2345: Argument of type 'BodyInit | null | undefined' is not assignable to parameter of type 'Document | XMLHttpRequestBodyInit | null | undefined'.
  Type 'ReadableStream<any>' is not assignable to type 'Document | XMLHttpRequestBodyInit | null | undefined'.

259     xhr.send(options.body)
                 ~~~~~~~~~~~~

node_modules/qiniu-js/src/utils/helper.ts:339:56 - error TS2339: Property 'mozURL' does not exist on type 'Window & typeof globalThis'.

339   const URL = window.URL || window.webkitURL || window.mozURL
                                                           ~~~~~~

node_modules/qiniu-js/src/utils/index.ts:8:36 - error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.

8 export { default as compressImage, CompressResult } from './compress'
                                     ~~~~~~~~~~~~~~


Found 21 errors in 6 files.

Errors  Files
     1  node_modules/qiniu-js/src/api/index.ts:84
     6  node_modules/qiniu-js/src/upload/base.ts:117
     6  node_modules/qiniu-js/src/upload/resume.ts:45
     2  node_modules/qiniu-js/src/utils/compress.ts:32
     5  node_modules/qiniu-js/src/utils/helper.ts:1
     1  node_modules/qiniu-js/src/utils/index.ts:8
@LUDA0831
Copy link

LUDA0831 commented Mar 2, 2023

同样的问题,请问有解决方法不

@junjiantech
Copy link
Author

同样的问题,请问有解决方法不

链接 中提供了两种方法, 经过验证后,确认可以通过 vuejs/language-tools#592 (reply in thread) 中提供的方法来解决。
具体可以通过如下步骤解决:

  1. 创建 '/stub/qiniu-js/index.d.ts' 文件

    // https://github.com/vuejs/language-tools/discussions/592
    export {};
  2. 配置 tsconfig.json 添加如下内容

    {
    	"compilerOptions": {
    		"skipLibCheck": true,
    		"paths": [
    			"qiniu-js/*": ["./stub/qiniu-js/index.d.ts"]
    		]
    	}
    }

@junjiantech
Copy link
Author

更多方案与使用细节参照: vuejs/language-tools#2018 (comment)

@LUDA0831
Copy link

LUDA0831 commented Mar 3, 2023

感谢,这样操作之后node_modules里面的错误是没了,但是也不能用包里的类型了,会报错
image

@LUDA0831
Copy link

LUDA0831 commented Mar 3, 2023

同样的问题,请问有解决方法不

链接 中提供了两种方法, 经过验证后,确认可以通过 vuejs/language-tools#592 (reply in thread) 中提供的方法来解决。 具体可以通过如下步骤解决:

  1. 创建 '/stub/qiniu-js/index.d.ts' 文件
    // https://github.com/vuejs/language-tools/discussions/592
    export {};
  2. 配置 tsconfig.json 添加如下内容
    {
    	"compilerOptions": {
    		"skipLibCheck": true,
    		"paths": [
    			"qiniu-js/*": ["./stub/qiniu-js/index.d.ts"]
    		]
    	}
    }

可以了,我把要用的类型复制到替换的d.ts里就好了,感谢感谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants