-
-
Notifications
You must be signed in to change notification settings - Fork 131
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
base: main
Are you sure you want to change the base?
Fix type errors #321
Conversation
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.
Why not make more types public? That would be a smaller PR, right?
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 |
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.
Which type?
That would cause a type error in the tests.
Nice, I like it. Note that TypeScript 5.5’s |
@remcohaszing @wooorm friendly ping 🔔 |
IMO this is good to go, although we might as well wait until TypeScript 5.5 now and use |
You describe this in your OP: “If private types are used, TypeScript will generate types for dependant packages that use relative paths.” The word private doesn’t seem right to me: if these types end up in the public API, they are thus publidc? If they are public, we should be expose to expose them too? I feel weird about this PR because it does different things, one part of which is it uses a style that we don‘t use anywhere in unified ( The other part of what this PR does (defining types in the root of a package) could perhaps be done and/or introduced everywhere, but I still wonder about my above point. And also if we’re going to do something along those lines, as I expression in the other issue, I am leaning more to using |
The following code does not re-export // index.js
/**
* @typedef {import('./lib/index.js').PrivateOptions} PublicOptions
*/ It defines a new type named // index.js
import { privateFunction } from './lib/index.js'
export function publicFunction(...args) {
return privateFunction(...args)
}
There are no type imports, type exports, nor type re-exports with types in JSDoc. Type imports are coming in TypeScript 5.5 though. Calling I want to provide a PoC for https://github.com/orgs/unifiedjs/discussions/238 once TypeScript 5.5 has been released, as that fixes some of the type issues we keep running into. |
Initial checklist
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 fromlib/index.js
toindex.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.