Skip to content

Fix d3-selection/focus failure with strictNullChecks=true#12340

Closed
alitaheri wants to merge 1 commit into
DefinitelyTyped:types-2.0from
alitaheri:fix-d3-null-check
Closed

Fix d3-selection/focus failure with strictNullChecks=true#12340
alitaheri wants to merge 1 commit into
DefinitelyTyped:types-2.0from
alitaheri:fix-d3-null-check

Conversation

@alitaheri
Copy link
Copy Markdown
Contributor

Please fill in this template.

  • Prefer to make your PR against the types-2.0 branch.
  • The package does not provide its own types, and you can not add them.
  • Test the change in your own code.
  • Follow the advice from the readme.
  • Avoid common mistakes.

If changing an existing definition:

  • Provide a URL to documentation or source code which provides context for the suggested changes: <>
  • Increase the version number in the header if appropriate.

@dt-bot
Copy link
Copy Markdown
Member

dt-bot commented Oct 29, 2016

d3-force/index.d.ts

to authors (@tomwanzek @gustavderdrache @borisyankov). Could you review this PR?
👍 or 👎?

Checklist

  • pass the Travis CI test?

d3-selection/index.d.ts

to authors (@tomwanzek @gustavderdrache @borisyankov). Could you review this PR?
👍 or 👎?

Checklist

  • pass the Travis CI test?

@tomwanzek
Copy link
Copy Markdown
Contributor

Thx, I will review shortly.

@ghost
Copy link
Copy Markdown

ghost commented Oct 29, 2016

Failing tests here are OK, they are fixed by #12344.

@tomwanzek
Copy link
Copy Markdown
Contributor

Pls do not merge before I reviewed. Thx. T

@alitaheri
Copy link
Copy Markdown
Contributor Author

@tomwanzek By the way, should I modifiy the BaseType or should I append | null where needed? I don't know the semantic for this. also, may I add strictNullChecks: true to tsconfig and update the tests while I'm at it?

@tomwanzek
Copy link
Copy Markdown
Contributor

@alitaheri The answer for d3-selection is not that straight-forward.

First of and for the sake of cross-referencing, this is related to the tracking issue #11365.

Enabling strictNullChecks in the tsconfig.json for any definition file, should only be done, after it has been vetted to enable strictNullChecks reliably. Otherwise, it gives the wrong impression to users.

For D3, in some cases the API documentation is explicit enough to understand on the issue of return values in "failure modes" or similar circumstances, like callback functions. In others, it is necessary to validate against the actual source code, to see whether e.g. the a function returns null or undefined if it does not return the "normal expected" return type SomeType. It may even be SomeType | null | undefined, or never.

I venture to say, it may not be as simple as adding null to the BaseType, I did some initial investigation a while back to see how things flow through callbacks, sub-selections, appends, inserts, enter, event handlers etc. in a Selection and there where additional considerations to follow up on.

So it will require going back to the documentation/source code. In any case the shape tests will have to be updated to ensure coverage of the strictNullChecks as well.

This was a primary reason to prioritize issue #11366 regarding adding JSDoc comments to all the definitions first.

In any case, because of the nature of the coupling between d3-selection, d3-transition, d3-selection-multi, d3-drag, d3-zoom. The update to strictNullChecks should be done for all of them with the same stroke to ensure consistency. Other D3 modules should be addressable in a more isolated manner.

@alitaheri alitaheri closed this Nov 8, 2016
@alitaheri alitaheri deleted the fix-d3-null-check branch November 8, 2016 18:42
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