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

TextEncoder in libdef but cannot be used, even though TextEncoder can be #8604

Closed
wchargin opened this issue Mar 3, 2021 · 1 comment
Closed
Assignees
Labels

Comments

@wchargin
Copy link
Contributor

wchargin commented Mar 3, 2021

Flow version: 0.145.0

Steps to reproduce

Brand new Yarn package with only flow-bin installed. In index.js:

// @flow
const util = require("util");
console.log(util.TextDecoder);
console.log(util.TextEncoder);

This is a straightforward use of the Node APIs, and works:

$ node index.js
[Function: TextDecoder]
[Function: TextEncoder]

Expected behavior

It should type-check.

Actual behavior

$ yarn flow --message-width 80
yarn run v1.22.10
$ /tmp/tmp.fTIX2thXuc/node_modules/.bin/flow --message-width 80
Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ index.js:4:18

Cannot get util.TextEncoder because property TextEncoder (did you mean
TextDecoder?) is missing in module util [1]. [prop-missing]

     index.js
        1│ // @flow
        2│ const util = require("util");
        3│ console.log(util.TextDecoder);
        4│ console.log(util.TextEncoder);
        5│

     ../flow/flowlib_812ef1ce4cab4593_1000/node.js
 [1] 2262│ declare module "util" {
     2263│   declare function debuglog(section: string): (data: any, ...args: any) => void;
     2264│   declare function format(format: string, ...placeholders: any): string;
     2265│   declare function log(string: string): void;
     2266│   declare function inspect(object: any, options?: util$InspectOptions): string;
     2267│   declare function isArray(object: any): boolean;
     2268│   declare function isRegExp(object: any): boolean;
     2269│   declare function isDate(object: any): boolean;
     2270│   declare function isError(object: any): boolean;
     2271│   declare function inherits(constructor: Function, superConstructor: Function): void;
     2272│   declare function deprecate(f: Function, string: string): Function;
     2273│   declare function promisify(f: Function): Function;
     2274│   declare function callbackify(f: Function): Function;
     2275│
     2276│   declare class TextDecoder {
     2277│     constructor(encoding?: string, options: {
     2278│       fatal?: boolean,
     2279│       ignoreBOM?: boolean,
     2280│       ...
     2281│     }): void;
     2282│     decode(input?: ArrayBuffer | DataView | $TypedArray, options?: { stream?: boolean, ... }): string;
     2283│     encoding: string;
     2284│     fatal: boolean;
     2285│     ignoreBOM: boolean;
     2286│   }
     2287│
     2288│   declare class TextEncoder {
     2289│     constructor(): void;
     2290│     encode(input?: string): Uint8Array;
     2291│     encoding: string;
     2292│   }
     2293│ }



Found 1 error
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Note that TextEncoder is declared, right after TextDecoder, as is
visible in the error trace. Both were added in #7713, first released in
v0.101.0; I can reproduce at that Flow version, too (and at v0.100.0 it
complains on both of them, as expected).

Can repro on Node 10 and Node 14.

Cannot repro on Flow Try (no such module util).

h/t @topocount for raising this issue

@noppa
Copy link
Contributor

noppa commented Apr 12, 2021

I'm guessing this is somehow because TextEncoder is also defined as a global type in streams.js libdef, whereas TextDecoder is not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants