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

Analysis does not match fs.readFileSync declaration #1870

Closed
bryannaegele opened this issue May 31, 2016 · 4 comments
Closed

Analysis does not match fs.readFileSync declaration #1870

bryannaegele opened this issue May 31, 2016 · 4 comments

Comments

@bryannaegele
Copy link

bryannaegele commented May 31, 2016

https://github.com/facebook/flow/blob/master/lib/node.js#L634 shows fs.readFileSync correctly returning type string when an encoding is passed.

Given this declaration:

declare module 'html-frontmatter' {
  declare var exports: (input: string) => {};
}

and this implementation:

import fs from 'fs'
import path from 'path'
import frontMatter from 'front-matter'
import objectAssign from 'object-assign'
import htmlFrontMatter from 'html-frontmatter'

let data
...
const html = fs.readFileSync(pagePath, 'utf-8')
data = objectAssign({}, htmlFrontMatter(html), { body: html })

Flow check raises this error

22:     data = objectAssign({}, htmlFrontMatter(html), { body: html })
                                 ^^^^^^^^^^^^^^^^^^^^^ function call
 22:     data = objectAssign({}, htmlFrontMatter(html), { body: html })
                                                 ^^^^ Buffer. This type is incompatible with
  2:   declare var exports: (input: string) => {};
                                    ^^^^^^ string. See lib: interfaces/html-frontmatter.js:2

and running flow suggest for the file resolves Buffer, as well.

-    const html = fs.readFileSync(pagePath, 'utf-8')
+    const html: Buffer = fs.readFileSync(pagePath, 'utf-8')

Are overloads working correctly?

Node 6.2.0
Flow 0.26

@mroch
Copy link
Contributor

mroch commented May 31, 2016

Overloads are tried in order and the first one to match wins. Since extra params are also allowed, that first one will match and the second one won't. :/

I think reversing the order of the overloads in lib/node.js will help. I can try it when I get into the office.

@bryannaegele
Copy link
Author

Thanks for the insight and tackling that @mroch.

@bryannaegele
Copy link
Author

@mroch I'm still seeing this issue with v0.27.

I also tried the non-shorthand object options to readFileSync fs.readFileSync(pagePath, { encoding: 'utf-8' }) but saw the same result.

@pitops
Copy link

pitops commented May 31, 2020

@bryannaegele how was this resolved? its 2020 and have the same issue.

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

Successfully merging a pull request may close this issue.

3 participants