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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: TypeScript definitions for Select component's onSelect / onDeselect props, update inaccurate docs #16344

Merged
merged 2 commits into from May 3, 2019

Conversation

Projects
None yet
2 participants
@mathieu-anderson
Copy link
Contributor

commented Apr 26, 2019

馃 This is a ...

  • New feature
  • Bug fix
  • Site / document update
  • Component style update
  • TypeScript definition update
  • Refactoring
  • Code style optimization
  • Test Case
  • Branch merge
  • Other (about what?)

馃懟 What's the background?

The SelectProps interface defines the value param for onSelect and onDeselect as SelectValue (https://github.com/ant-design/ant-design/blob/master/components/select/index.tsx#L50)

In the context of these handlers, as I understand it, value should never be an array, but always a single member of the array (string, number or LabeledValue). However, TS seems to not be able to correctly infer this. Therefore, typing the value param correctly in these handlers is not currently possible.

Moreover, the documentation seems to be inaccurate for the value, defaultValue and onDeselect props (especially as onDeselect does not get the option param, but is documented as such).

馃挕 Solution

  • Define the value param for onSelect and onDeselect as string|number|LabeledValue
  • Fix inaccurate documentation (partial update for CN docs : only type values)

馃摑 Changelog

  • English Changelog:
    • Select component : updated types for onSelect and onDeselect props to be string|number|LabeledValue
    • Update docs
  • Chinese Changelog (optional):

鈽戯笍 Self Check before Merge

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • TypeScript definition is updated/provided or not needed
  • Changelog is provided or not needed

@pr-triage pr-triage bot added the PR: unreviewed label Apr 26, 2019

@netlify

This comment has been minimized.

Copy link

commented Apr 26, 2019

Deploy preview for ant-design ready!

Built with commit 37ef5c3

https://deploy-preview-16344--ant-design.netlify.com

@codecov

This comment has been minimized.

Copy link

commented Apr 26, 2019

Codecov Report

Merging #16344 into master will decrease coverage by 0.04%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #16344      +/-   ##
==========================================
- Coverage   95.72%   95.67%   -0.05%     
==========================================
  Files         254      254              
  Lines        6990     6990              
  Branches     1962     1939      -23     
==========================================
- Hits         6691     6688       -3     
- Misses        298      301       +3     
  Partials        1        1
Impacted Files Coverage 螖
components/select/index.tsx 96.87% <酶> (酶) 猬嗭笍
components/_util/wave.tsx 85.84% <0%> (-2.84%) 猬囷笍

Continue to review full report at Codecov.

Legend - Click here to learn more
螖 = absolute <relative> (impact), 酶 = not affected, ? = missing data
Powered by Codecov. Last update 0350544...37ef5c3. Read the comment docs.

@mathieu-anderson mathieu-anderson changed the title fix: TypeScript definitions for Select component's onSelect / onDeselect props fix: TypeScript definitions for Select component's onSelect / onDeselect props, update inaccurate docs Apr 26, 2019

@@ -56,8 +56,8 @@ export interface SelectProps<T = SelectValue> extends AbstractSelectProps {
optionLabelProp?: string;
firstActiveValue?: string | string[];
onChange?: (value: T, option: React.ReactElement<any> | React.ReactElement<any>[]) => void;
onSelect?: (value: T, option: React.ReactElement<any>) => any;
onDeselect?: (value: T) => any;
onSelect?: (value: string | number | LabeledValue, option: React.ReactElement<any>) => any;

This comment has been minimized.

Copy link
@zombieJ

zombieJ Apr 28, 2019

Member

Define an type instead~

This comment has been minimized.

Copy link
@mathieu-anderson

mathieu-anderson Apr 28, 2019

Author Contributor

Good point, will do !

@zombieJ

This comment has been minimized.

Copy link
Member

commented Apr 28, 2019

CI failed. Merge master please.

@mathieu-anderson

This comment has been minimized.

Copy link
Contributor Author

commented Apr 29, 2019

Ugh sorry @zombieJ, made some kind of git commit history mess while fixing the build :|

@zombieJ

This comment has been minimized.

Copy link
Member

commented Apr 30, 2019

Seems it need rebase or cherry-pick to fix it.

@mathieu-anderson mathieu-anderson force-pushed the mathieu-anderson:fix-select-types branch from bb5d101 to 37ef5c3 May 3, 2019

@mathieu-anderson

This comment has been minimized.

Copy link
Contributor Author

commented May 3, 2019

@zombieJ cleaned up the git history, but the codebeat check seems to be stuck on pending. Does it require action?

@zombieJ zombieJ merged commit 6947d1b into ant-design:master May 3, 2019

26 of 29 checks passed

codebeat 6 issues resolved and 7 introduced
Details
Header rules No header rules processed
Details
Pages changed 211 new files uploaded
Details
CodeFactor No issues found.
Details
LGTM analysis: JavaScript No new or fixed alerts
Details
Mixed content No mixed content detected
Details
Redirect rules 18 redirect rules processed
Details
Semantic Pull Request ready to be squashed
Details
WIP Ready for review
Details
ant-design.ant-design #ant design succeeded
Details
buildsize No significant change
Details
ci/circleci: compile Your tests passed on CircleCI!
Details
ci/circleci: dist Your tests passed on CircleCI!
Details
ci/circleci: lint Your tests passed on CircleCI!
Details
ci/circleci: setup Your tests passed on CircleCI!
Details
ci/circleci: test_dist Your tests passed on CircleCI!
Details
ci/circleci: test_dist_15 Your tests passed on CircleCI!
Details
ci/circleci: test_dom Your tests passed on CircleCI!
Details
ci/circleci: test_dom_15 Your tests passed on CircleCI!
Details
ci/circleci: test_es Your tests passed on CircleCI!
Details
ci/circleci: test_es_15 Your tests passed on CircleCI!
Details
ci/circleci: test_lib Your tests passed on CircleCI!
Details
ci/circleci: test_lib_15 Your tests passed on CircleCI!
Details
ci/circleci: test_node Your tests passed on CircleCI!
Details
ci/circleci: test_node_15 Your tests passed on CircleCI!
Details
codecov/patch Coverage not affected when comparing 0350544...37ef5c3
Details
codecov/project 95.67% (-0.05%) compared to 0350544
Details
deploy/netlify Deploy preview ready!
Details
security/snyk - package.json (paranoidjk) No manifest changes detected

@pr-triage pr-triage bot added PR: merged and removed PR: unreviewed labels May 3, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can鈥檛 perform that action at this time.