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
feat(babel‑types): Add type definitions for Node assertion methods #11883
feat(babel‑types): Add type definitions for Node assertion methods #11883
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 6fecca5:
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/32321/ |
d942ed7
to
6d316c1
Compare
/ping @JLHwung |
packages/babel-types/package.json
Outdated
@@ -15,6 +15,11 @@ | |||
}, | |||
"main": "lib/index.js", | |||
"types": "lib/index.d.ts", | |||
"typesVersions": { | |||
">=3.7": { | |||
"lib/*.d.ts": ["lib/*.ts37.d.ts"] |
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.
nit: I think we can swap the name of ts37.d.ts
with index.d.ts
. So index.d.ts
always align to latest TS, and we can have lib/legacy.d.ts
as fallback.
{
"types": "lib/legacy.d.ts",
"typesVersions": {
">=3.7": {
"*": "lib/index.d.ts"
}
}
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 thing is, importing lib/index.js
directly would cause old TypeScript versions to try to load lib/index.d.ts
, but that would then have the TypeScript 3.7 syntax.
Using index.ts37.d.ts
also ensures that we can easily add index.tsXY.d.ts
(e.g.: index.ts40.d.ts
) in the future.
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.
We will disable submodule imports in Babel 8. And we could drop ts <3.0 support, too. So tsc
will always respect typeVersions
and types
and we can enforce that lib/index.d.ts
always aligns to latest TS while typeVersions
serves a fallback for older ts>=3
versions.
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.
typesVersions
is only supported since TypeScript 3.1.
Also, this will need to be kept as index.ts37.d.ts
in Babel 7.
0351f24
to
b9acb62
Compare
b9acb62
to
f468399
Compare
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
f468399
to
0dfaf46
Compare
I didn't notice this PR and did a9bc9be yesterday. However, this PR still added some improvements ( Thanks! |
This adds TypeScript and Flow type definitions for the
assert${typeName}
functions.It also makes use of the
typesVersions
field, which was introduced in TypeScript 3.1 to make theassert${typeName}
functions into assertion functions without breaking backwards compatibility, like what I did with@types/babel‑types
in DefinitelyTyped/DefinitelyTyped#45830.This also now generates
/** @deprecated */
JSDoc comments for deprecated node type checking functions.review?(@JLHwung, @MichaReiser, @nicolo-ribaudo)