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

Enforce type checking on babel-{cli,node} #14765

Merged
merged 9 commits into from Jul 20, 2022

Conversation

liuxingbaoyu
Copy link
Contributor

@liuxingbaoyu liuxingbaoyu commented Jul 18, 2022

Q                       A
Fixed Issues? Fixes #1, Fixes #2
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

These two packages seem to be left out.

I use a couple of @ts-expect-error because the imported packages have no or incorrect type definitions, but that doesn't matter because only one method belonging to them is used.

@liuxingbaoyu liuxingbaoyu added PR: Internal 🏠 A type of pull request used for our changelog categories pkg: cli pkg: node area: typescript labels Jul 18, 2022
packages/babel-cli/src/babel/dir.ts Outdated Show resolved Hide resolved
@@ -1,5 +1,7 @@
import convertSourceMap from "convert-source-map";
import { AnyMap, encodedMap } from "@jridgewell/trace-mapping";
import type { Section } from "@jridgewell/trace-mapping/dist/types/types";
Copy link
Contributor

@JLHwung JLHwung Jul 18, 2022

Choose a reason for hiding this comment

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

I am not comfortable with the undeclared package sub imports. @jridgewell Can you make the Section type public?

Copy link
Member

@jridgewell jridgewell Jul 20, 2022

Choose a reason for hiding this comment

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

Sure. Does this serve the need for now?

import type { SectionedSourceMap } from '@jridgewell/trace-mapping';
type Section = SectionedSourceMap['sections'][0]

Copy link
Contributor Author

@liuxingbaoyu liuxingbaoyu Jul 20, 2022

Choose a reason for hiding this comment

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

Yes, Thanks!

@@ -22,7 +23,7 @@ export function enable({ enableGlobbing }: { enableGlobbing: boolean }) {
stabilityThreshold: 50,
pollInterval: 10,
},
});
} as WatchOptions);
Copy link
Contributor

@JLHwung JLHwung Jul 18, 2022

Choose a reason for hiding this comment

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

Does const options: WatchOptions = { ... } work? Casting WatchOptions will mute any chokidar config errors.

Copy link
Contributor Author

@liuxingbaoyu liuxingbaoyu Jul 18, 2022

Choose a reason for hiding this comment

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

Yes it can, but it should be able to type check even with as WatchOptions.

Choose a reason for hiding this comment

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

IIUC using as is basically a cast, it will fail if the types are incompatible but it won't point out things like missing required properties.

@JLHwung JLHwung changed the title fix: Apply options of typescript to cli and node Enforce type checking on babel-{cli,node} Jul 18, 2022
Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com>
@babel-bot
Copy link
Collaborator

babel-bot commented Jul 18, 2022

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/52559/

lib/slash.d.ts Outdated Show resolved Hide resolved
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Approving but I would like to see #14765 (comment) resolved

filter?: (filename: string, index: number, dir: string) => boolean
): string[];
export = read;
}
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo Jul 19, 2022

Choose a reason for hiding this comment

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

As a follow-up, could you open a PR to update https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/fs-readdir-recursive/index.d.ts so that then we can use @types/fs-readdir-recursive?

Copy link
Contributor Author

@liuxingbaoyu liuxingbaoyu Jul 20, 2022

Choose a reason for hiding this comment

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

DefinitelyTyped/DefinitelyTyped#61344
Finish. I think we might be able to remove this package at some point.

packages/babel-node/src/_babel-node.ts Outdated Show resolved Hide resolved
liuxingbaoyu and others added 2 commits Jul 20, 2022
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
liuxingbaoyu and others added 2 commits Jul 20, 2022
Co-authored-by: Justin Ridgewell <justin@ridgewell.name>
@liuxingbaoyu liuxingbaoyu merged commit b807206 into babel:main Jul 20, 2022
38 checks passed
@liuxingbaoyu liuxingbaoyu deleted the ts-cli-node branch Jul 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: typescript pkg: cli pkg: node PR: Internal 🏠 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants