qiniu / nodejs-sdk

Qiniu Resource (Cloud) Storage SDK for Node.js
586 stars 190 forks source link

Typescript 编译 类型报错 #432

Closed zhc-l closed 1 month ago

zhc-l commented 3 months ago

mac@macdeMacBook-Pro chessAndCardRoomServer % yarn run build yarn run v1.22.19 $ rimraf dist && tsc && tsc-alias node_modules/qiniu/index.d.ts:1476:9 - error TS2411: Property 'scope' of type 'string | undefined' is not assignable to 'string' index type 'string | number | boolean'.

1476 scope?: string;


node_modules/qiniu/index.d.ts:1477:9 - error TS2411: Property 'isPrefixalScope' of type 'number | undefined' is not assignable to 'string' index type 'string | number | boolean'.

1477         isPrefixalScope?: number;

node_modules/qiniu/index.d.ts:1478:9 - error TS2411: Property 'expires' of type 'number | undefined' is not assignable to 'string' index type 'string | number | boolean'.

1478 expires?: number;


node_modules/qiniu/index.d.ts:1479:9 - error TS2411: Property 'insertOnly' of type 'number | undefined' is not assignable to 'string' index type 'string | number | boolean'.

1479         insertOnly?: number;

node_modules/qiniu/index.d.ts:1480:9 - error TS2411: Property 'saveKey' of type 'string | undefined' is not assignable to 'string' index type 'string | number | boolean'.

1480 saveKey?: string;


node_modules/qiniu/index.d.ts:1481:9 - error TS2411: Property 'forceSaveKey' of type 'boolean | undefined' is not assignable to 'string' index type 'string | number | boolean'.

1481         forceSaveKey?: boolean;

node_modules/qiniu/index.d.ts:1482:9 - error TS2411: Property 'endUser' of type 'string | undefined' is not assignable to 'string' index type 'string | number | boolean'.

1482 endUser?: string;


node_modules/qiniu/index.d.ts:1483:9 - error TS2411: Property 'returnUrl' of type 'string | undefined' is not assignable to 'string' index type 'string | number | boolean'.

1483         returnUrl?: string;

node_modules/qiniu/index.d.ts:1484:9 - error TS2411: Property 'returnBody' of type 'string | undefined' is not assignable to 'string' index type 'string | number | boolean'.

1484 returnBody?: string;


node_modules/qiniu/index.d.ts:1485:9 - error TS2411: Property 'callbackUrl' of type 'string | undefined' is not assignable to 'string' index type 'string | number | boolean'.

1485         callbackUrl?: string;

node_modules/qiniu/index.d.ts:1486:9 - error TS2411: Property 'callbackHost' of type 'string | undefined' is not assignable to 'string' index type 'string | number | boolean'.

1486 callbackHost?: string;


node_modules/qiniu/index.d.ts:1487:9 - error TS2411: Property 'callbackBody' of type 'string | undefined' is not assignable to 'string' index type 'string | number | boolean'.

1487         callbackBody?: string;

node_modules/qiniu/index.d.ts:1488:9 - error TS2411: Property 'callbackBodyType' of type 'string | undefined' is not assignable to 'string' index type 'string | number | boolean'.

1488 callbackBodyType?: string;


node_modules/qiniu/index.d.ts:1489:9 - error TS2411: Property 'callbackFetchKey' of type 'number | undefined' is not assignable to 'string' index type 'string | number | boolean'.

1489         callbackFetchKey?: number;

node_modules/qiniu/index.d.ts:1491:9 - error TS2411: Property 'persistentOps' of type 'string | undefined' is not assignable to 'string' index type 'string | number | boolean'.

1491 persistentOps?: string;


node_modules/qiniu/index.d.ts:1492:9 - error TS2411: Property 'persistentNotifyUrl' of type 'string | undefined' is not assignable to 'string' index type 'string | number | boolean'.

1492         persistentNotifyUrl?: string;

node_modules/qiniu/index.d.ts:1493:9 - error TS2411: Property 'persistentPipeline' of type 'string | undefined' is not assignable to 'string' index type 'string | number | boolean'.

1493 persistentPipeline?: string;


node_modules/qiniu/index.d.ts:1495:9 - error TS2411: Property 'fsizeLimit' of type 'number | undefined' is not assignable to 'string' index type 'string | number | boolean'.

1495         fsizeLimit?: number;

node_modules/qiniu/index.d.ts:1496:9 - error TS2411: Property 'fsizeMin' of type 'number | undefined' is not assignable to 'string' index type 'string | number | boolean'.

1496 fsizeMin?: number;


node_modules/qiniu/index.d.ts:1497:9 - error TS2411: Property 'mimeLimit' of type 'string | undefined' is not assignable to 'string' index type 'string | number | boolean'.

1497         mimeLimit?: string;

node_modules/qiniu/index.d.ts:1499:9 - error TS2411: Property 'detectMime' of type 'number | undefined' is not assignable to 'string' index type 'string | number | boolean'.

1499 detectMime?: number;


node_modules/qiniu/index.d.ts:1500:9 - error TS2411: Property 'deleteAfterDays' of type 'number | undefined' is not assignable to 'string' index type 'string | number | boolean'.

1500         deleteAfterDays?: number;

node_modules/qiniu/index.d.ts:1501:9 - error TS2411: Property 'fileType' of type 'number | undefined' is not assignable to 'string' index type 'string | number | boolean'.

1501 fileType?: number;


node_modules/qiniu/index.d.ts:1504:9 - error TS2411: Property 'transform' of type 'string | undefined' is not assignable to 'string' index type 'string | number | boolean'.

1504         transform?: string;

node_modules/qiniu/index.d.ts:1506:9 - error TS2411: Property 'transformFallbackMode' of type 'string | undefined' is not assignable to 'string' index type 'string | number | boolean'.

1506 transformFallbackMode?: string;


node_modules/qiniu/index.d.ts:1508:9 - error TS2411: Property 'transformFallbackKey' of type 'string | undefined' is not assignable to 'string' index type 'string | number | boolean'.

1508         transformFallbackKey?: string;

Found 26 errors in the same file, starting at: node_modules/qiniu/index.d.ts:1476

zhc-l commented 3 months ago

qiniu版本:^7.11.1

zhc-l commented 3 months ago

[key: string]: string | number | boolean | undefined;

PutPolicyOptions接口定义中索引签名需要加上undefined,本地临时解决 1

lihsai0 commented 3 months ago

@zhc-l 确实加上 undefined 会更严谨。会发个小版本来加上。

能否麻烦您提供一下您的 typescript 版本与 tsconfig.json?通过以下方式未能复现类型检查错误。

mkdir qiniu-nodejs-issue-432
cd qiniu-nodejs-issue-432
yarn add qiniu@7.11.1 typescript @types/node # typescirpt@5, @types/node@20
cat <<EOS > "put_policy.ts"
import * as qiniu from "qiniu";
const options: qiniu.rs.PutPolicyOptions = {
    scope: 'bucket',
};
const putPolicy = new qiniu.rs.PutPolicy(options);
console.log(putPolicy.getFlags());
EOS
./node_modules/.bin/tsc put_policy.ts && node put_policy.js
zhc-l commented 3 months ago

{ "compilerOptions": { "lib": ["ES2015", "ES2016"], "baseUrl": "./", "outDir": "dist", "target": "esnext", "module": "CommonJS", "moduleResolution": "Node", "noImplicitAny": false, "sourceMap": false, "esModuleInterop": true, "isolatedModules": false, "forceConsistentCasingInFileNames": true, "strictPropertyInitialization": false, "strict": true, "experimentalDecorators": true, "emitDecoratorMetadata": true

}

}

"typescript": "*"

lihsai0 commented 3 months ago

@zhc-l 建议您可以在 tsconfig.json 新增一个配置 skipLibCheck

{
    "compilerOptions": {
        "skipLibCheck": true
    }
}
lihsai0 commented 1 month ago

fixed in v7.12.0