Skip to content
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

[Feature Request] defaultScope... types add undefined keyword #206

Open
2 tasks done
Mister-Hope opened this issue Nov 28, 2024 · 4 comments
Open
2 tasks done

[Feature Request] defaultScope... types add undefined keyword #206

Mister-Hope opened this issue Nov 28, 2024 · 4 comments
Assignees
Labels
PR welcome Pull request welcome

Comments

@Mister-Hope
Copy link

βœ… Checklist

  • I am using the latest version
  • I have searched FAQ

πŸ“„ System Info

not needed

πŸ”Ž Description

image

The code is similar to the ones in docs: https://cz-git.qbb.sh/zh/recipes/default-scope#defaultscope

In another word, users can not guarantee a default scope could be inferred from the commit, and some thing like the following is too ugly, as the tool support undefined, it shall add it to types.

image

Note: You should also check other options as well as I believe similar issues might exist

πŸ”— Reproduction link / repo:

No response

@Mister-Hope Mister-Hope added the bug Something isn't working label Nov 28, 2024
@Zhengqbbb
Copy link
Owner

Zhengqbbb commented Nov 28, 2024

But I defined already includes undefined

image

@Mister-Hope
Copy link
Author

Mister-Hope commented Nov 28, 2024

I have a stricter tsconfig.json, where a?:type differs from a?:type|undefined, the former only allow to be absent, or with a exact type.

BTW, I suggest you opt-in this behavior in your project, as a: undefined might break the following:

const my plugin = ({ a = 1 }) => {
  // expect a to be number here
}

@Zhengqbbb
Copy link
Owner

πŸ˜… PR welcome

@Zhengqbbb Zhengqbbb added PR welcome Pull request welcome and removed bug Something isn't working labels Nov 28, 2024
@Zhengqbbb Zhengqbbb changed the title [Bug report] defaultScope should allow undefined [Feature Request] defaultScope... types add undefined keyword Nov 28, 2024
@Mister-Hope
Copy link
Author

Mister-Hope commented Dec 9, 2024

Ref: https://www.typescriptlang.org/tsconfig/#exactOptionalPropertyTypes This is recommended by typescript team so I would suggest you add this to your tsconfig.json and perform a full refactor.

The problem is that I am not sure if all options can be passed with undefined without causing issues, like I said before, declaring it may cause issues:

I suggest you opt-in this behavior in your project, as a: undefined might break the following:

const my plugin = ({ a = 1 }) => {
  // expect a to be number here
}

It's fine for me to send a PR fixing defaultScope ONLY, but I think a full check and fix should be better. :)

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

No branches or pull requests

2 participants