Skip to content

further restrict property descriptor type definitions#6316

Open
michaelficarra wants to merge 11 commits into
facebook:mainfrom
michaelficarra:patch-1
Open

further restrict property descriptor type definitions#6316
michaelficarra wants to merge 11 commits into
facebook:mainfrom
michaelficarra:patch-1

Conversation

@michaelficarra

Copy link
Copy Markdown

I was getting an error on this code due to a loose definition of property descriptors:

function safeWrite(obj: {}, prop: string, value: any) {
  let desc = Object.getOwnPropertyDescriptor(obj, prop);
  if (desc && 'value' in desc && (desc.writable || desc.configurable)) {
    desc.value = value;
    Object.defineProperty(obj, prop, desc);
  }
}

The error message was

Sketchy null check on boolean [1] which is potentially false. Perhaps you meant to check for null or undefined [1]?
(sketchy-null-bool)

     xxx.js
      8│
      9│ function safeWrite(obj: {}, prop: string, value: any) {
     10│   let desc = Object.getOwnPropertyDescriptor(obj, prop);
     11│   if (desc && 'value' in desc && (desc.writable || desc.configurable)) {
     12│     desc.value = value;
     13│     Object.defineProperty(obj, prop, desc);
     14│   }

     /tmp/flow/flowlib_16ab40eb/core.js
 [1] 27│     writable?: boolean;

@michaelficarra

Copy link
Copy Markdown
Author

It seems tests are failing because I haven't updated error offsets. How do I go about doing that? I can't find development documentation.

@mrkev

mrkev commented May 19, 2018

Copy link
Copy Markdown
Contributor

Hmm, let me bring this in and check it out. I can update the tests nw 👍

@facebook-github-bot facebook-github-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@mrkev has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@mrkev

mrkev commented May 24, 2018

Copy link
Copy Markdown
Contributor

Could you provide some documentation that backs up the changes you made here?

@michaelficarra

Copy link
Copy Markdown
Author

@mrkev Are you asking for me to add documentation to the PR or are you asking for me to provide you links to the sections of the spec that define the affected functions?

@mrkev

mrkev commented May 24, 2018

Copy link
Copy Markdown
Contributor

The latter one 👍 in a comment here or the description of the PR is good.

@michaelficarra

Copy link
Copy Markdown
Author

For more information about the Property Descriptor specification type, see https://tc39.github.io/ecma262/#sec-property-descriptor-specification-type.

ContraPropertyDescriptor represents the property descriptor-like objects accepted by APIs which manipulate property descriptors. These objects are converted to proper property descriptors by ToPropertyDescriptor.

CoPropertyDescriptor represents objects returned by APIs which read property descriptors. These objects are more restricted as each of the property descriptor's properties will always be present.

@michaelficarra

Copy link
Copy Markdown
Author

@mrkev I've provided the information that you asked for here. Can we get this merged?

@michaelficarra

Copy link
Copy Markdown
Author

@mrkev It's been another few months and I've yet again been having difficulties with Flow due to its loose typing of property descriptors. Is there anything else I can do to get this PR merged? I believe we just need to update error offsets, but there's no documentation on how to do that.

@michaelficarra

Copy link
Copy Markdown
Author

@mrkev I run into this issue nearly every time I write code that uses Flow. The implementation work here has already been done. Is there anything I can do to get somebody to merge this? I would think the Flow team would be more concerned about incorrect descriptions of JavaScript standard library APIs.

@nmote nmote added the Library definitions Issues or pull requests about core library definitions label Jan 3, 2019
@bakkot

bakkot commented Apr 19, 2019

Copy link
Copy Markdown

Ping @\maintainers. It's been another ~6 months.

@goodmind

Copy link
Copy Markdown
Contributor

@mrkev

@mrkev

mrkev commented May 7, 2019

Copy link
Copy Markdown
Contributor

@goodmind @thread been swamped with FB5 work. Probably won't be able to look at it for another while, sorry /:

@michaelficarra

Copy link
Copy Markdown
Author

@mrkev is there a different maintainer that can look at it? It's not a very complicated change.

@mrkev

mrkev commented Jun 27, 2019

Copy link
Copy Markdown
Contributor

Hop into the discord channel and ask there 👍

@nmote nmote self-assigned this Jun 27, 2019
@goodmind

Copy link
Copy Markdown
Contributor

/cc @nmote

@goodmind goodmind added the Stalled Issues and PRs that are stalled. label Jul 27, 2019
@bakkot

bakkot commented Nov 15, 2019

Copy link
Copy Markdown

Ping @nmote etc. It's been another ~6 months.

@nmote nmote removed their assignment Mar 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Library definitions Issues or pull requests about core library definitions Stalled Issues and PRs that are stalled.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants