-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
core: restructure types for direct import and publishing #14441
Conversation
types/env/global.d.ts
Outdated
@@ -0,0 +1,3 @@ | |||
export * from '../lh'; | |||
|
|||
export as namespace LH; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this to work, we shouldn't expose LH
globally at least in core. This is a temporary measure if we decide to split into multiple PRs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there an update on this? More PRs to come?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes in this PR should provide enough typings for the normal exposed api. We should still eliminate this global though.
Doing so would be done in a follow up, and probably wouldn't be a breaking change (although it would touch many files)
I had assumed we would solve #1773 with a limited set of types (our public interface), but since we're approaching year 6 for that issue and still no public API types, we should absolutely consider this approach :)
A few thoughts:
|
This idea sounds fine to me. Personally I like the filesystem organization where
I think this depends on where we decide to put the generated If the generated
I agree it's not ideal. However the alternative is to painstakingly go through every file and import the required types manually. Adding an
This is a good point. I intended this to be a follow up but it's not a bad idea to look into it now. |
Just in case we're speaking past each other, I meant as a pack/publish step. It's not useful to have them around otherwise.
Mixing ts and js files is pretty bad when the ts files aren't intended as source files, IMO, and makes the codebase less self evident. We're using But I'm like 80% sure the question is moot because having more than one importable path with an explicit
The best time to not use global variables is before you start, the second best time is now (or whenever they finally fix type module imports :) The The |
Ah yup, that makes sense.
I think I would support keeping our handwritten
Not sure I understand. Are you saying that |
@@ -31,6 +31,7 @@ jobs: | |||
node-version: 16.x | |||
|
|||
- run: yarn install --frozen-lockfile --network-timeout 1000000 | |||
- run: yarn type-check |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just better to do this earlier (failing sooner if types are bad), or was there some reason to move?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yarn type-check
is run as part of yarn build-all
now, that would have made yarn type-check
redundant and it would be confusing to receive type check errors as part of the build step.
Now we do the type check before building which fails sooner and caches types for the build step.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't come across any problems when using the types generated by this PR. Nice work! This should be so much better for our Node users.
Maybe add a note to |
If we don't want people to use them, maybe |
We're not quite there even for a basic user flow. Sprinkling in some more |
"@internal" is the right semantics. It'll at least show up as the first line of the jsdoc hover tooltip. A comment on the artifacts field is also good I think, let's do both?
I only verified IDE support looked good... which it does for user flows AFAICT. but yeah using tsc with nodenext and node16 is giving me various issues about file extensions missing:
|
(e2e test failure is unrelated) The errors @connorjclark noticed were valid and have been fixed in ba3104f. I also added a recipe doc + test for a project using typescript and nodenext module resolution 324012a. At this point, I think this PR is ready to merge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very exciting! 🎉
The test is a great addition. It's possible it will end up annoying detecting (additional) type errors in this roundabout way (does anyone run the docs tests except in CI?) but let's see if it's actually a problem and if there's more we can do to mitigate it (e.g. lint import paths in d.ts
files or whatever)
Proposal that helps us expose our types #1773
rsync
ed into the normal directory structure withyarn build-types
. This is done in prepack so should be in the release automatically.*.d.ts
that just modify the global namespace or module declarations are moved to thetypes/env
directory (i.e. types only we use).*.js
will need to doimport * as LH from '../types/lh.js'
in order for their generated type declarations to be valid. (seecore/index.js
for example)LH
from core*.d.ts
files.js
extension when importing*.d.ts
files in core