Skip to content

Commit

Permalink
Remove allowSyntheticDefaultImports (ant-design#8218)
Browse files Browse the repository at this point in the history
  • Loading branch information
yesmeck authored Nov 17, 2017
1 parent fdf0c11 commit 479a5cb
Show file tree
Hide file tree
Showing 143 changed files with 205 additions and 233 deletions.
5 changes: 5 additions & 0 deletions .jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@ module.exports = {
snapshotSerializers: [
'enzyme-to-json/serializer',
],
globals: {
'ts-jest': {
tsConfigFile: './tsconfig.test.json',
}
},
};
5 changes: 5 additions & 0 deletions .jest.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ module.exports = {
snapshotSerializers: [
'enzyme-to-json/serializer'
],
globals: {
'ts-jest': {
tsConfigFile: './tsconfig.test.json',
}
},
};
15 changes: 1 addition & 14 deletions README-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,7 @@ import 'antd/dist/antd.css'; // or 'antd/dist/antd.less'

## TypeScript

```js
// tsconfig.json
{
"compilerOptions": {
"moduleResolution": "node",
"jsx": "preserve",
"allowSyntheticDefaultImports": true
}
}
```

> 注意:
> - 设置 `allowSyntheticDefaultImports` 避免 `error TS1192: Module 'react' has no default export` 的错误。
> - 不要使用 @types/antd, antd 已经自带了 TypeScript 定义。
- 不要使用 @types/antd, antd 已经自带了 TypeScript 定义。

## 国际化

Expand Down
15 changes: 1 addition & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,7 @@ import 'antd/dist/antd.css'; // or 'antd/dist/antd.less'

### TypeScript

```js
// tsconfig.json
{
"compilerOptions": {
"moduleResolution": "node",
"jsx": "preserve",
"allowSyntheticDefaultImports": true
}
}
```

> Note:
> - set `allowSyntheticDefaultImports` to prevent `error TS1192: Module 'react' has no default export`.
> - Don't use @types/antd, antd provide a built-in ts definition already.
- Don't use @types/antd, antd provide a built-in ts definition already.

#### Use [ts-import-plugin](https://github.com/Brooooooklyn/ts-import-plugin) with modularized antd

Expand Down
5 changes: 5 additions & 0 deletions components/_util/callMoment.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// https://github.com/moment/moment/issues/3650

export default function callMoment(moment, ...args) {
return (moment.default || moment)(...args);
}
4 changes: 2 additions & 2 deletions components/affix/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import ReactDOM from 'react-dom';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import PropTypes from 'prop-types';
import addEventListener from 'rc-util/lib/Dom/addEventListener';
import classNames from 'classnames';
Expand Down
4 changes: 2 additions & 2 deletions components/alert/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import ReactDOM from 'react-dom';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import Animate from 'rc-animate';
import Icon from '../icon';
import classNames from 'classnames';
Expand Down
4 changes: 2 additions & 2 deletions components/anchor/Anchor.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import ReactDOM from 'react-dom';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import addEventListener from 'rc-util/lib/Dom/addEventListener';
Expand Down
2 changes: 1 addition & 1 deletion components/anchor/AnchorLink.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import * as React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

Expand Down
8 changes: 4 additions & 4 deletions components/auto-complete/InputElement.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { findDOMNode } from 'react-dom';
import * as React from 'react';
import * as ReactDOM from 'react-dom';

export interface InputElementProps {
children: React.ReactElement<any>;
Expand All @@ -9,10 +9,10 @@ export default class InputElement extends React.Component<InputElementProps, any
private ele: HTMLInputElement;

focus = () => {
this.ele.focus ? this.ele.focus() : (findDOMNode(this.ele) as HTMLInputElement).focus();
this.ele.focus ? this.ele.focus() : (ReactDOM.findDOMNode(this.ele) as HTMLInputElement).focus();
}
blur = () => {
this.ele.blur ? this.ele.blur() : (findDOMNode(this.ele) as HTMLInputElement).blur();
this.ele.blur ? this.ele.blur() : (ReactDOM.findDOMNode(this.ele) as HTMLInputElement).blur();
}
saveRef = (ele: HTMLInputElement) => {
this.ele = ele;
Expand Down
2 changes: 1 addition & 1 deletion components/auto-complete/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import * as React from 'react';
import { Option, OptGroup } from 'rc-select';
import classNames from 'classnames';
import Select, { AbstractSelectProps, SelectValue, OptionProps, OptGroupProps } from '../select';
Expand Down
4 changes: 2 additions & 2 deletions components/avatar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import ReactDOM from 'react-dom';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import Icon from '../icon';
import classNames from 'classnames';

Expand Down
2 changes: 1 addition & 1 deletion components/back-top/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import * as React from 'react';
import Animate from 'rc-animate';
import addEventListener from 'rc-util/lib/Dom/addEventListener';
import classNames from 'classnames';
Expand Down
2 changes: 1 addition & 1 deletion components/badge/ScrollNumber.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import * as React from 'react';
import { createElement, Component } from 'react';
import omit from 'omit.js';
import classNames from 'classnames';
Expand Down
2 changes: 1 addition & 1 deletion components/badge/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import * as React from 'react';
import PropTypes from 'prop-types';
import Animate from 'rc-animate';
import ScrollNumber from './ScrollNumber';
Expand Down
2 changes: 1 addition & 1 deletion components/breadcrumb/Breadcrumb.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import * as React from 'react';
import PropTypes from 'prop-types';
import { cloneElement } from 'react';
import warning from '../_util/warning';
Expand Down
2 changes: 1 addition & 1 deletion components/breadcrumb/BreadcrumbItem.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import * as React from 'react';
import PropTypes from 'prop-types';

export interface BreadcrumbItemProps {
Expand Down
2 changes: 1 addition & 1 deletion components/button/button-group.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import * as React from 'react';
import classNames from 'classnames';
import { ButtonSize } from './button';

Expand Down
2 changes: 1 addition & 1 deletion components/button/button.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import * as React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import omit from 'omit.js';
Expand Down
4 changes: 2 additions & 2 deletions components/calendar/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import moment from 'moment';
import * as React from 'react';
import * as moment from 'moment';
import { PREFIX_CLS } from './Constants';
import Select from '../select';
import { Group, Button } from '../radio';
Expand Down
8 changes: 5 additions & 3 deletions components/calendar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React from 'react';
import * as React from 'react';
import PropTypes from 'prop-types';
import moment from 'moment';
import * as moment from 'moment';
import FullCalendar from 'rc-calendar/lib/FullCalendar';
import LocaleReceiver from '../locale-provider/LocaleReceiver';
import { PREFIX_CLS } from './Constants';
import Header from './Header';
import callMoment from '../_util/callMoment';

declare const require: Function;

export { HeaderProps } from './Header';
Expand Down Expand Up @@ -71,7 +73,7 @@ export default class Calendar extends React.Component<CalendarProps, CalendarSta
constructor(props, context) {
super(props, context);

const value = props.value || props.defaultValue || moment();
const value = props.value || props.defaultValue || callMoment(moment);
if (!moment.isMoment(value)) {
throw new Error(
'The value/defaultValue of Calendar must be a moment object after `[email protected]`, ' +
Expand Down
2 changes: 1 addition & 1 deletion components/card/Grid.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import * as React from 'react';
import classNames from 'classnames';

export interface CardGridProps {
Expand Down
2 changes: 1 addition & 1 deletion components/card/Meta.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import * as React from 'react';
import classNames from 'classnames';

export interface CardMetaProps {
Expand Down
6 changes: 3 additions & 3 deletions components/card/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Component, Children } from 'react';
import * as React from 'react';
import classNames from 'classnames';
import addEventListener from 'rc-util/lib/Dom/addEventListener';
import omit from 'omit.js';
Expand Down Expand Up @@ -38,7 +38,7 @@ export interface CardProps {
onTabChange?: (key: string) => void;
}

export default class Card extends Component<CardProps, {}> {
export default class Card extends React.Component<CardProps, {}> {
static Grid: typeof Grid = Grid;
static Meta: typeof Meta = Meta;
resizeEvent: any;
Expand Down Expand Up @@ -93,7 +93,7 @@ export default class Card extends Component<CardProps, {}> {
}
isContainGrid() {
let containGrid;
Children.forEach(this.props.children, (element: JSX.Element) => {
React.Children.forEach(this.props.children, (element: JSX.Element) => {
if (element && element.type && element.type === Grid) {
containGrid = true;
}
Expand Down
2 changes: 1 addition & 1 deletion components/carousel/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import * as React from 'react';
import debounce from 'lodash.debounce';

// matchMedia polyfill for
Expand Down
2 changes: 1 addition & 1 deletion components/cascader/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import * as React from 'react';
import RcCascader from 'rc-cascader';
import arrayTreeFilter from 'array-tree-filter';
import classNames from 'classnames';
Expand Down
2 changes: 1 addition & 1 deletion components/checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import * as React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import RcCheckbox from 'rc-checkbox';
Expand Down
2 changes: 1 addition & 1 deletion components/checkbox/Group.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import * as React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import shallowEqual from 'shallowequal';
Expand Down
2 changes: 1 addition & 1 deletion components/collapse/Collapse.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import * as React from 'react';
import RcCollapse from 'rc-collapse';
import classNames from 'classnames';
import animation from '../_util/openAnimation';
Expand Down
2 changes: 1 addition & 1 deletion components/date-picker/Calendar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import * as React from 'react';
import CalendarLocale from 'rc-calendar/lib/locale/zh_CN';
import RcCalendar from 'rc-calendar';
import warning from 'warning';
Expand Down
7 changes: 4 additions & 3 deletions components/date-picker/RangePicker.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/* tslint:disable jsx-no-multiline-js */
import React from 'react';
import moment from 'moment';
import * as React from 'react';
import * as moment from 'moment';
import RangeCalendar from 'rc-calendar/lib/RangeCalendar';
import RcDatePicker from 'rc-calendar/lib/Picker';
import classNames from 'classnames';
import Icon from '../icon';
import warning from '../_util/warning';
import callMoment from '../_util/callMoment';

function getShowDateFromValue(value: moment.Moment[]): moment.Moment[] | undefined {
const [start, end] = value;
Expand Down Expand Up @@ -60,7 +61,7 @@ export default class RangePicker extends React.Component<any, any> {
const pickerValue = !value || isEmptyArray(value) ? props.defaultPickerValue : value;
this.state = {
value,
showDate: pickerValueAdapter(pickerValue || moment()),
showDate: pickerValueAdapter(pickerValue || callMoment(moment)),
open: props.open,
hoverValue: [],
};
Expand Down
6 changes: 3 additions & 3 deletions components/date-picker/WeekPicker.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component } from 'react';
import moment from 'moment';
import * as React from 'react';
import * as moment from 'moment';
import Calendar from 'rc-calendar';
import RcDatePicker from 'rc-calendar/lib/Picker';
import classNames from 'classnames';
Expand All @@ -9,7 +9,7 @@ function formatValue(value: moment.Moment | undefined, format: string): string {
return (value && value.format(format)) || '';
}

export default class WeekPicker extends Component<any, any> {
export default class WeekPicker extends React.Component<any, any> {
static defaultProps = {
format: 'YYYY-Wo',
allowClear: true,
Expand Down
7 changes: 4 additions & 3 deletions components/date-picker/createPicker.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react';
import moment from 'moment';
import * as React from 'react';
import * as moment from 'moment';
import MonthCalendar from 'rc-calendar/lib/MonthCalendar';
import RcDatePicker from 'rc-calendar/lib/Picker';
import classNames from 'classnames';
import omit from 'omit.js';
import Icon from '../icon';
import warning from '../_util/warning';
import callMoment from '../_util/callMoment';

export interface PickerProps {
value?: moment.Moment;
Expand Down Expand Up @@ -104,7 +105,7 @@ export default function createPicker(TheCalendar): any {
disabledTime={disabledTime}
locale={locale.lang}
timePicker={props.timePicker}
defaultValue={props.defaultPickerValue || moment()}
defaultValue={props.defaultPickerValue || callMoment(moment)}
dateInputPlaceholder={placeholder}
prefixCls={prefixCls}
className={calendarClassName}
Expand Down
4 changes: 2 additions & 2 deletions components/date-picker/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import moment from 'moment';
import * as React from 'react';
import * as moment from 'moment';
import RcCalendar from 'rc-calendar';
import MonthCalendar from 'rc-calendar/lib/MonthCalendar';
import createPicker from './createPicker';
Expand Down
2 changes: 1 addition & 1 deletion components/date-picker/wrapPicker.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import * as React from 'react';
import TimePickerPanel from 'rc-time-picker/lib/Panel';
import classNames from 'classnames';
import LocaleReceiver from '../locale-provider/LocaleReceiver';
Expand Down
2 changes: 1 addition & 1 deletion components/divider/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import * as React from 'react';
import classNames from 'classnames';

export default function Divider({
Expand Down
2 changes: 1 addition & 1 deletion components/dropdown/dropdown-button.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import * as React from 'react';
import Button from '../button';
import { ButtonGroupProps } from '../button/button-group';
import Icon from '../icon';
Expand Down
6 changes: 3 additions & 3 deletions components/dropdown/dropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { cloneElement } from 'react';
import * as React from 'react';
import RcDropdown from 'rc-dropdown';
import classNames from 'classnames';
import DropdownButton from './dropdown-button';
Expand Down Expand Up @@ -46,15 +46,15 @@ export default class Dropdown extends React.Component<DropDownProps, any> {

render() {
const { children, prefixCls, overlay, trigger, disabled } = this.props;
const dropdownTrigger = cloneElement(children as any, {
const dropdownTrigger = React.cloneElement(children as any, {
className: classNames((children as any).props.className, `${prefixCls}-trigger`),
disabled,
});
// menu cannot be selectable in dropdown defaultly
const overlayProps = overlay && (overlay as any).props;
const selectable = (overlayProps && 'selectable' in overlayProps)
? overlayProps.selectable : false;
const fixedModeOverlay = cloneElement(overlay as any, {
const fixedModeOverlay = React.cloneElement(overlay as any, {
mode: 'vertical',
selectable,
});
Expand Down
Loading

0 comments on commit 479a5cb

Please sign in to comment.