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

chore: Extract SwitchChangeEventHandler and SwitchSize #17331

Merged
merged 1 commit into from
Jun 27, 2019

Conversation

yesmeck
Copy link
Member

@yesmeck yesmeck commented Jun 27, 2019

With this change, we can define a change handler more convenience:

Before:

const handleChange = (checked: boolean, event: MouseEvent) => {
  ...
}

After:

const handleChange: SwitchChangeEventHandler = (checked, event) => {
  ...
}

🤔 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?

💡 Solution

📝 Changelog

Language Changelog
🇺🇸 English Improve type definitions of Switch
🇨🇳 Chinese 改进 Switch 的类型定义

☑️ 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

With this change, we can define change handler more convenience:

Before:

```javascript
const handleChange = (checked: boolean, event: MouseEvent) => {
  ...
}
```

After:

```javascript
const handleChange: SwitchChangeEventHandler = (checked, event) => {
  ...
}
```
@netlify
Copy link

netlify bot commented Jun 27, 2019

Deploy preview for ant-design ready!

Built with commit 87afda5

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

export interface SwitchProps {
prefixCls?: string;
size?: 'small' | 'default';
Copy link
Member

Choose a reason for hiding this comment

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

这种有没有更好的声明方式,Enum 能用不?

Copy link
Member Author

Choose a reason for hiding this comment

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

export enum SwitchSize {
  SMALL = 'small';
  DEFAUL = 'default';
}
import { SwitchSize } from 'antd/es/switch';

<Switch size={SwitchSize.SMALL} />

Copy link
Member

Choose a reason for hiding this comment

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

这样就改使用方式了。

目前看来最好的方式是:#7965 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

他那种assert不推荐的,毕竟assert能少用就少用。如果值A是B类型,你应该直接声明A是B类型,而不是把A里的类型都assert成B里的属性然后通过ts的类型检查。

@afc163 afc163 changed the title Extract SwitchChangeEventHandler and SwitchSize chore: Extract SwitchChangeEventHandler and SwitchSize Jun 27, 2019
@afc163 afc163 merged commit c391515 into master Jun 27, 2019
@delete-merged-branch delete-merged-branch bot deleted the improve-swicth-types branch June 27, 2019 15:02
@afc163 afc163 mentioned this pull request Jun 29, 2019
14 tasks
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.

None yet

3 participants