metro icon indicating copy to clipboard operation
metro copied to clipboard

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

Open nickhudkins opened this issue 2 months ago • 1 comments

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.

nickhudkins avatar Nov 08 '25 01:11 nickhudkins

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

nickhudkins avatar Nov 08 '25 17:11 nickhudkins