Typescript: Incorrect usage of Union Typing (mostly options)
@aleksandar-cloudinary 已经在做这个了。
开始于 2023年5月28日。
评估
这个 Issue 还没有评估数据。
描述
Describe the bug in a sentence or two.
Many options type arguments are using union when the intention is an intersection.
Issue Type (Can be multiple)
- Build - Can’t install or import the SDK
- Babel - Babel errors or cross browser issues
- Performance - Performance issues
- Behaviour - Functions aren’t working as expected (Such as generate URL)
- Documentation - Inconsistency between the docs and behaviour
- Incorrect Types - For typescript users who are having problems with our d.ts files
- Other (Specify)
Steps to reproduce
An example using the ConfigAndUrlOptions type.
import { v2 as cloudinary, ConfigAndUrlOptions } from 'cloudinary';
const options: ConfigAndUrlOptions = {
version: "1",
cloud_name: "something",
// ConfigOptions type is `boolean`, here it is a string
force_version: "true",
};
// look at typescript tooltip for the options object
cloudinary.url('puclic_id', options);
This example will not fail to compile. However, force_version is provided as a string.
Correct Usage
Instead of a union, the ConfigAndUrlOptions object should be an intersection.
import { v2 as cloudinary, ConfigOptions, UrlOptions } from 'cloudinary';
type ConfigAndUrlOptions = ConfigOptions & UrlOptions;
const options: ConfigAndUrlOptions = {
version: "1",
cloud_name: "something",
// typescript compile error, wrong type provided
force_version: "true",
};
cloudinary.url('puclic_id', options);
Wrap Up
There are a lot of unions being mis-used this way. I'm happy to help create a PR. However, doing so would take significant time for me.
- 主要语言
- JavaScript
- 星标
- 672
- 派生
- 318
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
cloudinary/cloudinary_npm 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 45/100
cloudinary/cloudinary_npm#746 · 1 条评论 ·
-
难度 5/5 一周以上 新手友好度 30/100
cloudinary/cloudinary_npm#739 ·
-
难度 2/5 1-3 小时 新手友好度 58/100
cloudinary/cloudinary_npm#734 ·
-
难度 5/5 一周以上 新手友好度 25/100
cloudinary/cloudinary_npm#713 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 45/100
cloudinary/cloudinary_npm#712 · 1 条评论 ·
查看 cloudinary/cloudinary_npm 的全部 Issue
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 88/100
-
discovery:other factory-active task-identify-harness-labels-done task-identify-issue-type-done
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
needs-triage typo
难度 1/5 1 小时以内 新手友好度 88/100
llm-d-incubation/llm-d-scaling-manager#122 ·
维护者通常 1 天内回复
-
flag: invalid template issue: bug severity: low source: cli status: pending reproduction version: 5
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 2 天内回复
-
meta
难度 1/5 1 小时以内 新手友好度 88/100
matrix-org/matrix.org#3774 ·
维护者通常 1 天内回复