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

Fix type errors #321

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Fix type errors #321

wants to merge 3 commits into from

Conversation

remcohaszing
Copy link
Member

Initial checklist

  • I read the support docs
  • I read the contributing guide
  • I agree to follow the code of conduct
  • I searched issues and couldn’t find anything (or linked relevant results below)
  • If applicable, I’ve added docs and tests

Description of changes

Since typical usage of unified-lint-rule involves inferring the type based on a function call, the inferred type should be public. If private types are used, TypeScript will generate types for dependant packages that use relative paths.

To solve this, public types in unified-lint-rule were moved from lib/index.js to index.js. lintRule only uses these public types.

The severity can be set as a boolean. To support this, the Label type now accepts a boolean type.

Two tests explicitly test bad input. These are annotated with a @ts-expect-error comment.

Since typical usage of `unified-lint-rule` involves inferring the type
based on a function call, the inferred type should be public. If private
types are used, TypeScript will generate types for dependant packages
that use relative paths.

To solve this, public types in `unified-lint-rule` were moved from
`lib/index.js` to `index.js`. `lintRule` only uses these public types.

The severity can be set as a boolean. To support this, the `Label` type
now accepts a boolean type.

Two tests explicitly test bad input. These are annotated with a
`@ts-expect-error` comment.
@remcohaszing remcohaszing added 🐛 type/bug This is a problem 👶 semver/patch This is a backwards-compatible fix ☂️ area/types This affects typings 🤞 phase/open Post is being triaged manually labels Apr 23, 2024
@wooorm
Copy link
Member

wooorm commented Apr 24, 2024

Since typical usage of unified-lint-rule involves inferring the type based on a function call, the inferred type should be public. If private types are used, TypeScript will generate types for dependant packages that use relative paths.

Why not make more types public? That would be a smaller PR, right?

The severity can be set as a boolean. To support this, the Label type now accepts a boolean type.

Can you do this in a separate PR? That way, we can focus on how to solve completely broken types here.


Also, you can use import('package-name') instead of import('../index.js'), with export maps.
I prefer that, as it shows that something is from the public API instead of from a private internal lib file.

This makes it clear the type is public. It also implicitly acts as a
test this type is public.
This is how it was previously exposed.
@remcohaszing
Copy link
Member Author

Why not make more types public? That would be a smaller PR, right?

Which type? SeverityTuple is only used internally.

Can you do this in a separate PR? That way, we can focus on how to solve completely broken types here.

That would cause a type error in the tests.

Also, you can use import('package-name') instead of import('../index.js'), with export maps. I prefer that, as it shows that something is from the public API instead of from a private internal lib file.

Nice, I like it.


Note that TypeScript 5.5’s @import annotation will allow us to add the type imports on top instead of using import('module').Type type annotations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
☂️ area/types This affects typings 🤞 phase/open Post is being triaged manually 👶 semver/patch This is a backwards-compatible fix 🐛 type/bug This is a problem
Development

Successfully merging this pull request may close these issues.

None yet

2 participants