From 27ac8b1d91682bc3ea293d9740170ba0fa2f3587 Mon Sep 17 00:00:00 2001 From: Avan Date: Tue, 20 Aug 2024 02:25:20 +0800 Subject: [PATCH] fix: tsc noEmit (#481) --- .gitignore | 4 ++- docs/examples/arrowContent.tsx | 4 +-- docs/examples/formError.tsx | 11 +++++-- docs/examples/onVisibleChange.tsx | 7 ++++- docs/examples/showArrow.tsx | 3 +- docs/examples/simple.tsx | 52 ++++++++++++++++++++----------- src/Tooltip.tsx | 1 + tests/index.test.tsx | 2 +- 8 files changed, 57 insertions(+), 27 deletions(-) diff --git a/.gitignore b/.gitignore index 35fad32..93e1cbd 100644 --- a/.gitignore +++ b/.gitignore @@ -39,4 +39,6 @@ package-lock.json # dumi .dumi/tmp -.dumi/tmp-production \ No newline at end of file +.dumi/tmp-production + +bun.lockb \ No newline at end of file diff --git a/docs/examples/arrowContent.tsx b/docs/examples/arrowContent.tsx index 938d75a..a5ed068 100644 --- a/docs/examples/arrowContent.tsx +++ b/docs/examples/arrowContent.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { CSSProperties } from 'react'; import Tooltip from 'rc-tooltip'; import '../../assets/bootstrap_white.less'; @@ -11,7 +11,7 @@ const styles = { background: '#f6f6f6', verticalAlign: 'middle', border: '5px solid white', -}; +} as CSSProperties; const rowStyle = { display: 'table-row', diff --git a/docs/examples/formError.tsx b/docs/examples/formError.tsx index 7bc44f7..20b9b3b 100644 --- a/docs/examples/formError.tsx +++ b/docs/examples/formError.tsx @@ -1,12 +1,17 @@ -import React, { Component } from 'react'; import Tooltip from 'rc-tooltip'; +import React, { Component } from 'react'; import '../../assets/bootstrap.less'; +interface TestState { + visible: boolean; + destroy?: boolean; +} + class Test extends Component { state = { visible: false, - }; + } as TestState; handleDestroy = () => { this.setState({ @@ -14,7 +19,7 @@ class Test extends Component { }); }; - handleChange = e => { + handleChange = (e) => { this.setState({ visible: !e.target.value, }); diff --git a/docs/examples/onVisibleChange.tsx b/docs/examples/onVisibleChange.tsx index bf75dd3..094b3ed 100644 --- a/docs/examples/onVisibleChange.tsx +++ b/docs/examples/onVisibleChange.tsx @@ -6,10 +6,15 @@ function preventDefault(e) { e.preventDefault(); } +interface TestState { + visible: boolean; + destroy?: boolean; + } + class Test extends Component { state = { visible: false, - }; + } as TestState; onVisibleChange = visible => { this.setState({ diff --git a/docs/examples/showArrow.tsx b/docs/examples/showArrow.tsx index 882f6bf..0f7f94a 100644 --- a/docs/examples/showArrow.tsx +++ b/docs/examples/showArrow.tsx @@ -1,3 +1,4 @@ +import type { CSSProperties } from 'react'; import React from 'react'; import Tooltip from 'rc-tooltip'; import '../../assets/bootstrap_white.less'; @@ -11,7 +12,7 @@ const styles = { background: '#f6f6f6', verticalAlign: 'middle', border: '5px solid white', -}; +} as CSSProperties; const rowStyle = { display: 'table-row', diff --git a/docs/examples/simple.tsx b/docs/examples/simple.tsx index dedf321..ad284aa 100644 --- a/docs/examples/simple.tsx +++ b/docs/examples/simple.tsx @@ -1,9 +1,23 @@ -import React, { Component } from 'react'; +import type { ActionType } from '@rc-component/trigger'; +import type { OffsetType } from '@rc-component/trigger/lib/interface'; import Tooltip from 'rc-tooltip'; +import type { CSSProperties } from 'react'; +import React, { Component } from 'react'; import '../../assets/bootstrap.less'; import { placements } from '../../src/placements'; -class Test extends Component { +interface TestState { + destroyTooltipOnHide: boolean; + destroyTooltipOptions: { name: string; value: number }[]; + placement: string; + transitionName: string; + trigger: Record; + offsetX?: OffsetType; + offsetY?: OffsetType; + overlayInnerStyle?: CSSProperties; +} + +class Test extends Component { state = { destroyTooltipOnHide: false, destroyTooltipOptions: [ @@ -24,13 +38,15 @@ class Test extends Component { transitionName: 'rc-tooltip-zoom', trigger: { hover: 1, - }, + click: 0, + focus: 0, + } as Record, offsetX: placements.right.offset[0], offsetY: placements.right.offset[1], overlayInnerStyle: undefined, }; - onPlacementChange = e => { + onPlacementChange = (e) => { const placement = e.target.value; const { offset } = placements[placement]; this.setState({ @@ -40,13 +56,13 @@ class Test extends Component { }); }; - onTransitionChange = e => { + onTransitionChange = (e) => { this.setState({ transitionName: e.target.checked ? e.target.value : '', }); }; - onTriggerChange = e => { + onTriggerChange = (e) => { const { trigger } = this.state; if (e.target.checked) { trigger[e.target.value] = 1; @@ -58,38 +74,38 @@ class Test extends Component { }); }; - onOffsetXChange = e => { + onOffsetXChange = (e) => { const targetValue = e.target.value; this.setState({ offsetX: targetValue || undefined, }); }; - onOffsetYChange = e => { + onOffsetYChange = (e) => { const targetValue = e.target.value; this.setState({ offsetY: targetValue || undefined, }); }; - onVisibleChange = visible => { + onVisibleChange = (visible) => { console.log('tooltip', visible); // eslint-disable-line no-console }; - onDestroyChange = e => { + onDestroyChange = (e) => { const { value } = e.target; this.setState({ - destroyTooltipOnHide: [false, { keepParent: false }, { keepParent: true }][value], + destroyTooltipOnHide: [false, { keepParent: false }, { keepParent: true }][value] as boolean, }); }; onOverlayInnerStyleChange = () => { - this.setState(prevState => ({ + this.setState((prevState) => ({ overlayInnerStyle: prevState.overlayInnerStyle ? undefined : { background: 'red' }, })); }; - preventDefault = e => { + preventDefault = (e) => { e.preventDefault(); }; @@ -102,7 +118,7 @@ class Test extends Component {