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

chore: fully type check packages/*/src files #117

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

Conversation

JoshuaKGoldberg
Copy link
Contributor

@JoshuaKGoldberg JoshuaKGoldberg commented Sep 3, 2024

Prerequisites checklist

What is the purpose of this pull request?

Creates a root-level tsconfig.json that can type check all project files, along with a ci.yml step to do so in CI.

What changes did you make? (Give an overview)

This PR includes two common TypeScript practices for monorepos:

  • A tsconfig.base.json: to unify & share the common TSConfig settings used by all projects
  • A root-level tsconfig.json: so editors have that includes all files

That root-level tsconfig.json is necessary for typed linting with the recommended typescript-eslint project service, as noted by @snitin315 and myself as a followup in #90 -> #90 (comment).

Also fixes a few type errors here and there. I'm posting comments in the PR.

Notably, this PR does not set up project references. Doing so requires touching files on disk, which I'm not confident enough in this repo to do on my own unprompted. Instead, the root-level tsconfig.json has noEmit: true so it's purely used for type checking.

Related Issues

Followup to #90, which is a PR. Would the team like me to file more granular issues? I wasn't sure how much the team wants some or all of this change. My intent is to continue enabling strict TypeScript flags after this, unless directed otherwise.

Is there anything you'd like reviewers to focus on?

I'm applying the practices I see as common + good in TypeScript-land, but am not totally sure I interpreted the existing repo setup right. Very much seeking to understand. 🙂

tsconfig.base.json Outdated Show resolved Hide resolved
types/levn.d.ts Outdated Show resolved Hide resolved
@JoshuaKGoldberg JoshuaKGoldberg marked this pull request as ready for review September 3, 2024 22:30
.github/workflows/ci.yml Outdated Show resolved Hide resolved
CONTRIBUTING.md Outdated Show resolved Hide resolved
CONTRIBUTING.md Show resolved Hide resolved
types/levn.d.ts Outdated Show resolved Hide resolved
Co-authored-by: Nicholas C. Zakas <[email protected]>
package.json Outdated Show resolved Hide resolved
@nzakas
Copy link
Member

nzakas commented Oct 18, 2024

@JoshuaKGoldberg are you still working on this?

@JoshuaKGoldberg
Copy link
Contributor Author

Yes! I'd been waiting on #118 to get resolved. Cleaning this up now.

@fasttime
Copy link
Member

fasttime commented Nov 3, 2024

@JoshuaKGoldberg there's a merge conflict now.

- name: Install Packages
run: |
npm install
npm run build
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doubt: why are we running a build? aren't we type checking on source?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The types definition files aren't there until we build.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that is so, doesn't package build step fail when the type is wrong for the package? 🤔 do we need another tsc command to run separately on the main repo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that is true. That's a pain I've just dealt with in other repos. In theory we could do a strategy like || 0 to ignore any failures.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to re iterate, my doubt was why we'd need to run build command and test:types on source files?

  • the build process itself has a in-built tsc check? if the build fails then tsc is also expected to fail?
  • we cannot have a tsc check separately because its dependent on build (which in itself has a tsc check?)

now the question resolves to do we have any other ts files apart from the ts files that are built in the repo? if yes then its better to have a tsc for fallback

(sorry for the confusion 😅)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. I hadn't noticed that test:types just runs tsc...for some reason I had it in my head that there was something else running there.

So yes, npm run build actually runs tsc, so we don't need something separate running tsc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just clarifying - is there a request for changes?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there's no need to run tsc separately because that's already happening via npm run build.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah got it. Thanks, I see now - sorry for giving you the runaround harish-sethuraman.

@fasttime
Copy link
Member

@JoshuaKGoldberg just a reminder that there are some comments for you to address in this PR. There's also a merge conflict.

@JoshuaKGoldberg
Copy link
Contributor Author

👍 on the merge conflict, fixed. I'm not clear on what else I need to do - asked inline. Thanks for the ping.

Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Would like @fasttime to review before merging.

Copy link
Member

@harish-sethuraman harish-sethuraman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for clarifying regarding the build / typecheck step Josh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Second Review Needed
Development

Successfully merging this pull request may close these issues.

5 participants