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

Add buffer class to node.js interface #108

Merged
merged 2 commits into from
Nov 26, 2014

Conversation

rsolomo
Copy link
Contributor

@rsolomo rsolomo commented Nov 22, 2014

No description provided.

slice(start?: number, end?: number): Buffer;
fill(value: string | number, offset?: number, end?: number): void;
inspect(): string;
toString(encoding?: string, start?: number, end?: number): string;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The toString override here did not have the effect I was expecting.

The following still passes flow check even after the changes:

/* @flow */
function test(): string {
  var buf = new Buffer('a');
  return buf.toString({}, {}, {})
}

Is this expected behavior?

@avikchaudhuri
Copy link
Contributor

toString is currently special-cased to accept anything and return true.

@@ -8,7 +8,59 @@
*
*/

type Buffer = any; // TODO
declare class Buffer {
constructor(value: Array<number> | number | string, encoding?: string): void;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems worthwhile to use overloading here at least for the (str, encoding) constructor -- since the other two versions of the constructor don't have a second parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had initially tried that approach, but found that the type system was not behaving as I thought it would with overloaded constructors.

For example, given a declaration like this:

declare class Buffer {
  constructor(array: Array<number>): void;
  constructor(size: number): void;
  constructor(string: string, encoding?: string): void;
}

The following was still passing type check:

/* @flow */
var b = new Buffer(null)

@jeffmo
Copy link
Contributor

jeffmo commented Nov 25, 2014

This is awesome, thanks for doing this!

avikchaudhuri added a commit that referenced this pull request Nov 26, 2014
Add buffer class to node.js interface
@avikchaudhuri avikchaudhuri merged commit 921cc99 into facebook:master Nov 26, 2014
@ptmt ptmt mentioned this pull request Dec 20, 2014
jeffmo pushed a commit to jeffmo/flow that referenced this pull request Jul 31, 2015
…sions

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

Successfully merging this pull request may close these issues.

3 participants