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

Arbitrary properties of function object have type any #106

Closed
dmitry-vsl opened this issue Nov 22, 2014 · 8 comments
Closed

Arbitrary properties of function object have type any #106

dmitry-vsl opened this issue Nov 22, 2014 · 8 comments
Labels
enhancement Typing: soundness No false negatives (type checker claims that there is no error in the incorrect program)

Comments

@dmitry-vsl
Copy link

dmitry-vsl commented Nov 22, 2014

Search keywords: function, statics

Flow finds no error in the following code:

/* @flow */
function noop(){}
console.log(noop.foo/noop.bar);

I think it is a bug because both noop.foo and noop.bar are undefined.

@avikchaudhuri
Copy link
Contributor

Known issue, will fix. (A function has an underlying object that stores its static properties; in general we keep objects created inside a module extensible, so we don't immediately error out on property accesses because they may be defined in other parts of the file the type checker hasn't yet visited. But we should be stricter in cases like the one you point out.)

@ghost
Copy link

ghost commented Aug 4, 2015

Thank you for reporting this issue and appreciate your patience. We've notified the core team for an update on this issue. We're looking for a response within the next 30 days or the issue may be closed.

@savv
Copy link

savv commented Sep 24, 2015

Would be curious to hear if there's an update on this.

@StyMaar
Copy link

StyMaar commented Jun 1, 2016

Any news on this ?

@nmn
Copy link
Contributor

nmn commented Mar 4, 2017

@avikchaudhuri Do you think defaulting to ?mixed instead of any will be easy to do for this? That seems to solve the problem.

jfirebaugh added a commit to mapbox/mapbox-gl-js that referenced this issue Sep 28, 2017
Properties on function types are currently unsound in flow: facebook/flow#106
jfirebaugh added a commit to mapbox/mapbox-gl-js that referenced this issue Sep 28, 2017
Properties on function types are currently unsound in flow: facebook/flow#106
jfirebaugh added a commit to mapbox/mapbox-gl-js that referenced this issue Sep 28, 2017
Properties on function types are currently unsound in flow: facebook/flow#106
@joelochlann
Copy link
Contributor

Just re-activating this thread, by pointing out that this weakness in Flow's type system does lead to real-world bugs, particularly around the use of promises.

For instance:

function getPromise(): Promise<boolean> {
  return Promise.resolve(true)
}

// type-checks, works at runtime
getPromise().then(() => true);

// type-checks, fails at runtime
getPromise.then(() => true);

https://flow.org/try/#0GYVwdgxgLglg9mABAcwKZQAoCc4FsYDOqAFAJQBci2ehqAPAEZxwA2qAhmAHyIDeAUIkRZ0ILEmr4iAOhEFWANxJQsIVKX4BffvzSYcUkqWlQAFqjDEyiALw8Va0gG5d6SbRPnL1u4gfqnIA

I understand that functions are ultimately objects in JavaScript, but so are arrays, and they have stricter type-checking in Flow. Why not functions too?

// type-checks, fails at runtime
({}).blah(() => 'hey')

// type-checks, fails at runtime
(() => {}).blah(() => 'hey')

// doesn't type-check, fails at runtime
[].blah(() => 'hey')

Any insights you can give into the decisions around this would be much appreciated!

@kangax
Copy link

kangax commented Jun 22, 2019

@avikchaudhuri I see you mentioned 5 years ago that this will be fixed. Just pinging to see if there's any progress :D

@gkz
Copy link
Member

gkz commented Oct 27, 2022

Fixed 0.187

@gkz gkz closed this as completed Oct 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Typing: soundness No false negatives (type checker claims that there is no error in the incorrect program)
Projects
None yet
Development

No branches or pull requests

9 participants