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

feat(babel‑types): Add type definitions for Node assertion methods #11883

Conversation

ExE-Boss
Copy link
Contributor

@ExE-Boss ExE-Boss commented Jul 28, 2020

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

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 the assert${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)

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 28, 2020

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:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration

@babel-bot
Copy link
Collaborator

babel-bot commented Jul 28, 2020

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

@ExE-Boss ExE-Boss force-pushed the feat/babel-types/add-type-definitions-for-assertion-methods branch from d942ed7 to 6d316c1 Compare July 28, 2020 15:43
@JLHwung JLHwung self-requested a review July 28, 2020 15:51
@ExE-Boss
Copy link
Contributor Author

/ping @JLHwung

@@ -15,6 +15,11 @@
},
"main": "lib/index.js",
"types": "lib/index.d.ts",
"typesVersions": {
">=3.7": {
"lib/*.d.ts": ["lib/*.ts37.d.ts"]
Copy link
Contributor

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"
    }
}

Copy link
Contributor Author

@ExE-Boss ExE-Boss Aug 27, 2020

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.

Copy link
Contributor

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.

Copy link
Contributor Author

@ExE-Boss ExE-Boss Aug 27, 2020

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.

@ExE-Boss ExE-Boss force-pushed the feat/babel-types/add-type-definitions-for-assertion-methods branch from 0351f24 to b9acb62 Compare August 27, 2020 15:43
@ExE-Boss ExE-Boss mentioned this pull request Oct 16, 2020
@nicolo-ribaudo nicolo-ribaudo force-pushed the feat/babel-types/add-type-definitions-for-assertion-methods branch from b9acb62 to f468399 Compare November 10, 2020 14:46
@nicolo-ribaudo nicolo-ribaudo added pkg: types PR: Internal 🏠 A type of pull request used for our changelog categories labels Nov 10, 2020
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
@nicolo-ribaudo nicolo-ribaudo force-pushed the feat/babel-types/add-type-definitions-for-assertion-methods branch from f468399 to 0dfaf46 Compare November 10, 2020 14:47
@nicolo-ribaudo
Copy link
Member

I didn't notice this PR and did a9bc9be yesterday. However, this PR still added some improvements (assert* definitions for older TS versions, and @deprecated annotations) so I have rebased it.

Thanks! 😄

@nicolo-ribaudo nicolo-ribaudo merged commit 3505eaa into babel:main Nov 10, 2020
@nicolo-ribaudo nicolo-ribaudo deleted the feat/babel-types/add-type-definitions-for-assertion-methods branch November 10, 2020 15:42
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Feb 10, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: types 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

4 participants