metro icon indicating copy to clipboard operation
metro copied to clipboard

fix(types): incorrect <void> use in typescript

Open nickhudkins opened this issue 2 months ago • 3 comments

Summary

The use of void as a type parameter is semantically different in TS than Flow. Specifically, providing void in Flow will result in the use of the default type parameter value, while TS will treat it as an explicit use of void for the generic.

Original Issue: https://github.com/facebook/metro/issues/1491

Changelog: [Fix] Bundler types (transformFile) [Fix] IncrementalBundler types (OutputGraph, getDeltaBundler, getDependencies, buildGraph, initializeGraph and updateGraph) [Fix] Worker types (transform) [Fix] Metro.buildGraph return type

Test plan

Oof. This may be a larger discussion as keeping the TS and Flow types in-sync and correct may be a moving target as the project evolves. For now, the verification is "when consuming this code in a TS codebase, types are the same as if I was consuming the flow annotated code"

nickhudkins avatar Nov 07 '25 15:11 nickhudkins

Thanks @nickhudkins!

Several Metro packages do now have automatic TS types, but there are a few patterns unsupported by the translator and/or TS itself so we've been refactoring and touching up package-by-package to get translations working (any PRs to get us closer would be appreciated as well!). metro-config for example is automatic and validated in CI, but metro isn't.

https://github.com/facebook/metro/blob/main/scripts/generateTypeScriptDefinitions.js#L29

robhogan avatar Nov 07 '25 15:11 robhogan

I actually saw this and began down the path of doing type generation for metro, let me see if I can take an incremental approach here!

nickhudkins avatar Nov 07 '25 19:11 nickhudkins

Alrighty... metro types are gonna take some more significant work, especially just trying to reconcile flow types with typescript, especially those that have spreads at the end

nickhudkins avatar Nov 08 '25 01:11 nickhudkins