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

Add declarations for more of @babel/types exports #10504

Conversation

Jessidhia
Copy link
Member

Q                       A
Patch: Bug Fix?
Major: Breaking Change? not yet
Minor: New Feature? 👍
Tests Added + Pass? do we even have infrastructure for testing types?
Documentation PR Link
Any Dependency Changes?
License MIT

This adds lots of missing declarations to the types of @babel/types,
including many utility functions useful to plugin authors.

With the typescript types, I tried to make them as useful as possible
for control flow analysis / inference, but Flow doesn't seem to
support overloads and I'm not as familiar with it anyway so it has
simpler types.

`// export function assert${typeName}(node: object | null | undefined, opts?: object | null): asserts ${
result === "boolean" ? "node" : result
};`
);
}

lines.push(
Copy link
Member Author

@Jessidhia Jessidhia Sep 27, 2019

Choose a reason for hiding this comment

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

I think this whole thing would be much nicer to modify if there was, say, a typescript.template.d.ts file that is complete enough to be typechecked and with placeholder comments / types for where the generated types should get injected; the generator script then just needs to slurp the template and edit it.

It'd also get us prettier for free.

@Jessidhia Jessidhia force-pushed the add-more-babel-types-export-declarations branch from 937a656 to b60ec41 Compare October 4, 2019 10:11
This adds lots of missing declarations to the types of @babel/types,
including many utility functions useful to plugin authors.

With the typescript types, I tried to make them as useful as possible
for control flow analysis / inference, but Flow doesn't seem to
support overloads and I'm not as familiar with it anyway so it has
simpler types.
@Jessidhia Jessidhia force-pushed the add-more-babel-types-export-declarations branch from b60ec41 to 6e8ad67 Compare October 4, 2019 10:27
@Jessidhia
Copy link
Member Author

Jessidhia commented Oct 4, 2019

CircleCI's build failed.... because it ran out of memory? o_O

 FAIL  packages/babel-plugin-proposal-decorators/test/index.js
  ● Test suite failed to run

    ENOMEM: not enough memory, read

      8111 | 
      8112 | function _isInteger() {
    > 8113 |   const data = _interopRequireDefault(require("lodash/isInteger"));
           |                                       ^
      8114 | 
      8115 |   _isInteger = function () {
      8116 |     return data;

      at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:443:43)
      at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:513:25)
      at _isInteger (packages/babel-generator/lib/printer.js:8113:39)

@nicolo-ribaudo
Copy link
Member

Yeah it's flaky


lines.push(
`export function is${typeName}(node: object | null | undefined, opts?: object | null): ${result};`,
// TypeScript 3.7: https://github.com/microsoft/TypeScript/pull/32695 will allow assert declarations
Copy link
Member Author

Choose a reason for hiding this comment

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

We can use typesVersions to publish typings for typescript <3.7 and typescript >=3.7 at the same time, but we'll need to generate types twice.

I want to refactor the typescript generation to use .d.ts files as templates (to make it much easier to get editor feedback while modifying them) so I can try to do that at the same time.

@nicolo-ribaudo nicolo-ribaudo self-requested a review October 7, 2019 10:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: flow area: typescript outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: types PR: New Feature 🚀 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

2 participants