Repository navigation
fix(flow): a Flow library's declarations are globals of the files Flow reads - #3165
Merged
Merged
Conversation
…w reads `stream: ReadableStream` in react's Flow files stopped linking to `declare class ReadableStream` in `flow-typed/environments/streams.js`. PR #2736 keeps a type a module doesn't import to its own file, a declaration file or a `declare global` block, and a Flow library is none of them: a `.js` script of `declare` statements. The types a Flow library declares were lost on every file. PR #2736 never shipped. Fix: a `.js` script with a top-level `declare` statement is a Flow library, its `declare module.exports` no CommonJS export, and its top level global to the JavaScript files Flow reads, which see it as they see a `.d.ts`. A TypeScript file doesn't: its `ReadableStream` is TypeScript's own. A library's own bare type names are held to the same rule, and a top-level call `declare(...)` is no statement. Validation: tests fail on main and pass here. A/B against 4499d00: react 207 added, 3 false removed (a `Function` to an enum member, an `HTMLElement` to a property); metro 174 added (`Buffer`, `http$IncomingMessage`, Jest's types), 5 false removed; excalidraw, vscode-be, express, taxonomy, flask, gin identical. Index CPU: level (see the PR). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
stream: ReadableStreamin react's Flow files stopped linking todeclare class ReadableStreaminflow-typed/environments/streams.js. PR #2736 keeps atype a module doesn't import to its own file, a declaration file or a
declare globalblock, and a Flow library is none of them: a.jsscript ofdeclarestatements. The types a Flow library declares were lost on every file. PR #2736
never shipped.
Fix: a
.jsscript with a top-leveldeclarestatement is a Flow library, itsdeclare module.exportsno CommonJS export, and its top level global to theJavaScript files Flow reads, which see it as they see a
.d.ts. A TypeScriptfile doesn't: its
ReadableStreamis TypeScript's own. A library's own baretype names are held to the same rule, and a top-level call
declare(...)is nostatement.
Validation
4499d007:All grouped by name and read. react:
ReadableStream82,ConsoleTask54,AsyncLocalStorage36,WritableStream20,ExtensionRuntimePort13. metro:Buffer125, Jest's types,http$IncomingMessage,ws$WebSocket. Removed, all false: a Flow library'sFunctionlinked to an enum member and to adeclare moduleblock's alias, andHTMLElementto a property.97cd3800, all six on4499d007: 853 files passed, 6 skipped; 10,610 tests passed, 2 expected fail, 87 skipped, 0 failed; 4 workers, Vitest 4.1.11,CODEGRAPH_KERNEL_EXPECT=1. This PR's own test files pass on this head.🤖 Generated with Claude Code