Skip to content

chore(types): auto-generate types for metro-file-map#1611

Closed
nickhudkins wants to merge 5 commits intofacebook:mainfrom
nickhudkins:types/metro-file-map
Closed

chore(types): auto-generate types for metro-file-map#1611
nickhudkins wants to merge 5 commits intofacebook:mainfrom
nickhudkins:types/metro-file-map

Conversation

@nickhudkins
Copy link
Contributor

Summary

As I began working to hand-fix some types, the formidable @robhogan pointed me in the direction of generateTypeScriptDefinitions.js, which has been used here to generate types for metro-file-map

Changelog:
[Fix]: Auto generate types for metro-file-map

Test plan

Automatically tested in CI, also peformed a good-ol eyeball check.

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 8, 2025
@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Nov 8, 2025
@nickhudkins nickhudkins force-pushed the types/metro-file-map branch 2 times, most recently from 8ee7e05 to 2d6edcb Compare November 8, 2025 01:54
@nickhudkins
Copy link
Contributor Author

There are a few failures here, some are easily fixable, others will take some finagling.

1.) IntervalID and TimeoutID, we can simply exclude them with /*:: */ to avoid problems for now, I think the fields wouldn't ever be public anyway.
2.) Incomplete third-party types. For example fb-watchman has types defined in flow-typed. flow-api-translator does NOT play nicely with this.

Option 1: Use @types/fb-watchman

  • 😔 these types are less complete than the types in flow-typed, and leave us with remaining errors.
  • We could contribute these types back upstream and wait.

Option 2: Some Naive Tooling!

  • flow-api-translator will happily convert MOST of those types, but the contents need to be unwrapped from: declare module '{{ moduleId }}' { ...definitions... }.
  • The declare module.exports: syntax also needs translation.

Note

I have a local script that performs these pre-processing steps to be able to successfully generate TS at least for fb-watchman. It is all naive string matching. Maybe this is fine.

Option 3: Make flow-api-translator "Just Work"
This would be neat, but I am unsure if it is worth the investment

Copy link
Contributor Author

@nickhudkins nickhudkins left a comment

Choose a reason for hiding this comment

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

Mostly dropping comments for myself so I don't lose track, but also for anyone reading this, perhaps my commentary is helpful.

@nickhudkins nickhudkins force-pushed the types/metro-file-map branch 3 times, most recently from 1243041 to 5060eb0 Compare November 12, 2025 17:48

beforeEach(() => {
jest.resetModules();
// Re-require the worker module to reset its internal state.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

what? get rid of you

}>;

type V8Serializable = interface {};
type V8Serializable = unknown;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need @robhogan input on how we want to treat interface {}, Since the type itself is not exported, and expects a generic, unknown does seem "fine", though I assume there should be some constraint on this type.


export type WorkerSetupArgs = $ReadOnly<{}>;
export interface WorkerSetupArgs {
__future__?: false;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is another one of those "doesn't translate to TS well" (empty object types), at the moment tossed in a field, but realistically there is probably a better type all together?


const NOT_A_DOT = '(?<!\\.\\s*)';
const CAPTURE_STRING_LITERAL = (pos /*: number */) =>
const CAPTURE_STRING_LITERAL = (pos: number) =>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe this is a file that needs to be CommonJS, though interestingly making this change did not cause test failures beyond the shape of the exports changing from using export default instead of module.exports

]);

module.exports = extensions;
export default extensions;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

similar to other files that were CommonJS, these might end up with errors that aren't reproduced within this repo.

'**/node_modules/**',
'packages/metro-babel-register/**',
'packages/*/build/**',
'packages/metro-file-map/src/worker.js',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Needs to remain CommonJS?
Node version + vm.runScript usage in tests makes this tricky. We can omit it from generation for now, use the escape hatch from my other PR and hand define some types until we can actually convert it to ESM

@meta-codesync
Copy link
Contributor

meta-codesync bot commented Jan 13, 2026

@robhogan has imported this pull request. If you are a Meta employee, you can view this in D90583383.

@meta-codesync
Copy link
Contributor

meta-codesync bot commented Jan 26, 2026

@robhogan merged this pull request in 356848d.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants