Skip to content

Commit

Permalink
chore: optimize tsconfig (alibaba#1513)
Browse files Browse the repository at this point in the history
* chore: optimize tsconfig

* fix: tslint 校验不通过

* fix: tslint 校验不通过

* chore: ts fix

* chore: add production ts config

Co-authored-by: 尽龙 <[email protected]>
  • Loading branch information
crazylxr and brickspert authored Mar 22, 2022
1 parent 7c076d4 commit 258282b
Show file tree
Hide file tree
Showing 37 changed files with 92 additions and 74 deletions.
6 changes: 3 additions & 3 deletions docs/guide/dom.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Most of the DOM Hooks will receive the `target` parameter, which indicates the e

```ts
export default () => {
const ref = useRef();
const ref = useRef(null);
const isHovering = useHover(ref);
return <div ref={ref}>{isHovering ? 'hover' : 'leaveHover'}</div>;
};
Expand Down Expand Up @@ -38,8 +38,8 @@ In addition, **the `target` of DOM Hooks supports dynamic changes**. for example
export default () => {
const [boolean, { toggle }] = useBoolean();

const ref = useRef();
const ref2 = useRef();
const ref = useRef(null);
const ref2 = useRef(null);

const isHovering = useHover(boolean ? ref : ref2);
return (
Expand Down
6 changes: 3 additions & 3 deletions docs/guide/dom.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ahooks 大部分 DOM 类 Hooks 都会接收 `target` 参数,表示要处理的

```ts
export default () => {
const ref = useRef();
const ref = useRef(null);
const isHovering = useHover(ref);
return <div ref={ref}>{isHovering ? 'hover' : 'leaveHover'}</div>;
};
Expand Down Expand Up @@ -38,8 +38,8 @@ export default () => {
export default () => {
const [boolean, { toggle }] = useBoolean();

const ref = useRef();
const ref2 = useRef();
const ref = useRef(null);
const ref2 = useRef(null);

const isHovering = useHover(boolean ? ref : ref2);
return (
Expand Down
6 changes: 3 additions & 3 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ gulp.task('clean', async function () {
});

gulp.task('cjs', function () {
const tsProject = ts.createProject('tsconfig.json', {
const tsProject = ts.createProject('tsconfig.pro.json', {
module: 'CommonJS',
});
return tsProject
Expand All @@ -25,7 +25,7 @@ gulp.task('cjs', function () {
});

gulp.task('es', function () {
const tsProject = ts.createProject('tsconfig.json', {
const tsProject = ts.createProject('tsconfig.pro.json', {
module: 'ESNext',
});
return tsProject
Expand All @@ -40,7 +40,7 @@ gulp.task('es', function () {
});

gulp.task('declaration', function () {
const tsProject = ts.createProject('tsconfig.json', {
const tsProject = ts.createProject('tsconfig.pro.json', {
declaration: true,
emitDeclarationOnly: true,
});
Expand Down
5 changes: 5 additions & 0 deletions packages/hooks/src/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module '*.jpg';

interface Window {
TEST_SCRIPT?: any;
}
2 changes: 1 addition & 1 deletion packages/hooks/src/useAsyncEffect/demo/demo1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function mockCheck(): Promise<boolean> {
}

export default () => {
const [pass, setPass] = useState<boolean>(null);
const [pass, setPass] = useState<boolean>();

useAsyncEffect(async () => {
setPass(await mockCheck());
Expand Down
4 changes: 2 additions & 2 deletions packages/hooks/src/useAsyncEffect/demo/demo2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ function mockCheck(val: string): Promise<boolean> {

export default () => {
const [value, setValue] = useState('');
const [pass, setPass] = useState<boolean>(null);
const [pass, setPass] = useState<boolean>();

useAsyncEffect(
async function* () {
setPass(null);
setPass(undefined);
const result = await mockCheck(value);
yield; // Check whether the effect is still valid, if it is has been cleaned up, stop at here.
setPass(result);
Expand Down
2 changes: 1 addition & 1 deletion packages/hooks/src/useClickAway/demo/demo1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useClickAway } from 'ahooks';

export default () => {
const [counter, setCounter] = useState(0);
const ref = useRef<HTMLButtonElement>();
const ref = useRef<HTMLButtonElement>(null);
useClickAway(() => {
setCounter((s) => s + 1);
}, ref);
Expand Down
4 changes: 2 additions & 2 deletions packages/hooks/src/useClickAway/demo/demo3.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { useClickAway } from 'ahooks';

export default () => {
const [counter, setCounter] = useState(0);
const ref1 = useRef();
const ref2 = useRef();
const ref1 = useRef(null);
const ref2 = useRef(null);
useClickAway(() => {
setCounter((s) => s + 1);
}, [ref1, ref2]);
Expand Down
2 changes: 1 addition & 1 deletion packages/hooks/src/useClickAway/demo/demo4.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useClickAway } from 'ahooks';

export default () => {
const [counter, setCounter] = useState(0);
const ref = useRef<HTMLButtonElement>();
const ref = useRef<HTMLButtonElement>(null);
useClickAway(
() => {
setCounter((s) => s + 1);
Expand Down
2 changes: 1 addition & 1 deletion packages/hooks/src/useClickAway/demo/demo5.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useClickAway } from 'ahooks';

export default () => {
const [counter, setCounter] = useState(0);
const ref = useRef();
const ref = useRef(null);
useClickAway(
() => {
setCounter((s) => s + 1);
Expand Down
4 changes: 2 additions & 2 deletions packages/hooks/src/useDrop/demo/demo1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import React, { useRef, useState } from 'react';
import { useDrop, useDrag } from 'ahooks';

const DragItem = ({ data }) => {
const dragRef = useRef();
const dragRef = useRef(null);

const [dragging, setDragging] = useState(false);

Expand Down Expand Up @@ -42,7 +42,7 @@ const DragItem = ({ data }) => {
export default () => {
const [isHovering, setIsHovering] = useState(false);

const dropRef = useRef();
const dropRef = useRef(null);

useDrop(dropRef, {
onText: (text, e) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/hooks/src/useEventListener/demo/demo1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useEventListener } from 'ahooks';

export default () => {
const [value, setValue] = useState(0);
const ref = useRef();
const ref = useRef(null);

useEventListener(
'click',
Expand Down
2 changes: 1 addition & 1 deletion packages/hooks/src/useExternal/demo/demo1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default () => {
Status: <b>{status}</b>
</p>
<p>
Response: <i>{status === 'ready' ? TEST_SCRIPT?.start() : '-'}</i>
Response: <i>{status === 'ready' ? window.TEST_SCRIPT?.start() : '-'}</i>
</p>
</>
);
Expand Down
2 changes: 1 addition & 1 deletion packages/hooks/src/useFocusWithin/demo/demo1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useFocusWithin } from 'ahooks';
import { message } from 'antd';

export default () => {
const ref = useRef();
const ref = useRef(null);
const isFocusWithin = useFocusWithin(ref, {
onFocus: () => {
message.info('focus');
Expand Down
2 changes: 1 addition & 1 deletion packages/hooks/src/useFullscreen/demo/demo1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import React, { useRef } from 'react';
import { useFullscreen } from 'ahooks';

export default () => {
const ref = useRef();
const ref = useRef(null);
const [isFullscreen, { enterFullscreen, exitFullscreen, toggleFullscreen }] = useFullscreen(ref);
return (
<div ref={ref} style={{ background: 'white' }}>
Expand Down
13 changes: 10 additions & 3 deletions packages/hooks/src/useHistoryTravel/demo/demo2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@ import { useHistoryTravel } from 'ahooks';
import React, { useState } from 'react';

export default () => {
const { value, setValue, backLength, forwardLength, back, forward, go, reset } = useHistoryTravel(
['do homework'],
);
const {
value = [],
setValue,
backLength,
forwardLength,
back,
forward,
go,
reset,
} = useHistoryTravel(['do homework']);

const [inputValue, setInputValue] = useState('');
const [step, setStep] = useState(-1);
Expand Down
2 changes: 1 addition & 1 deletion packages/hooks/src/useHover/demo/demo1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import React, { useRef } from 'react';
import { useHover } from 'ahooks';

export default () => {
const ref = useRef();
const ref = useRef(null);
const isHovering = useHover(ref);
return <div ref={ref}>{isHovering ? 'hover' : 'leaveHover'}</div>;
};
2 changes: 1 addition & 1 deletion packages/hooks/src/useInViewport/demo/demo1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import React, { useRef } from 'react';
import { useInViewport } from 'ahooks';

export default () => {
const ref = useRef();
const ref = useRef(null);
const [inViewport] = useInViewport(ref);
return (
<div>
Expand Down
8 changes: 5 additions & 3 deletions packages/hooks/src/useInfiniteScroll/demo/mutate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ export default () => {
} = useRequest(deleteItem, {
manual: true,
onSuccess: (_, [id]) => {
const index = data.list.findIndex((i) => i === id);
data.list.splice(index, 1);
mutate({ ...data });
if (data) {
const index = data.list.findIndex((i) => i === id);
data?.list.splice(index, 1);
mutate({ ...data });
}
},
});

Expand Down
2 changes: 1 addition & 1 deletion packages/hooks/src/useInfiniteScroll/demo/scroll.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function getLoadMoreList(nextId: string | undefined, limit: number): Promise<Res
}

export default () => {
const ref = useRef<HTMLDivElement>();
const ref = useRef<HTMLDivElement>(null);

const { data, loading, loadMore, loadingMore, noMore } = useInfiniteScroll(
(d) => getLoadMoreList(d?.nextId, 4),
Expand Down
2 changes: 1 addition & 1 deletion packages/hooks/src/useInterval/demo/demo2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useInterval } from 'ahooks';

export default () => {
const [count, setCount] = useState(0);
const [interval, setInterval] = useState(1000);
const [interval, setInterval] = useState<number | undefined>(1000);

useInterval(() => {
setCount(count + 1);
Expand Down
2 changes: 1 addition & 1 deletion packages/hooks/src/useKeyPress/demo/demo5.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import React, { useState, useRef } from 'react';
import { useKeyPress } from 'ahooks';

export default () => {
const inputRef = useRef();
const inputRef = useRef(null);

const [text, setText] = useState('');
const [textRef, setTextRef] = useState('');
Expand Down
2 changes: 1 addition & 1 deletion packages/hooks/src/useLongPress/demo/demo1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useLongPress } from 'ahooks';

export default () => {
const [counter, setCounter] = useState(0);
const ref = useRef<HTMLButtonElement>();
const ref = useRef<HTMLButtonElement>(null);

useLongPress(() => setCounter((s) => s + 1), ref);

Expand Down
2 changes: 1 addition & 1 deletion packages/hooks/src/useLongPress/demo/demo2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default () => {
const [pressCounter, setPressCounter] = useState(0);
const [clickCounter, setClickCounter] = useState(0);

const ref = useRef<HTMLButtonElement>();
const ref = useRef<HTMLButtonElement>(null);

useLongPress(() => setPressCounter((s) => s + 1), ref, {
onClick: () => setClickCounter((s) => s + 1),
Expand Down
2 changes: 1 addition & 1 deletion packages/hooks/src/useMouse/demo/demo2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import React, { useRef } from 'react';
import { useMouse } from 'ahooks';

export default () => {
const ref = useRef();
const ref = useRef(null);
const mouse = useMouse(ref.current);

return (
Expand Down
2 changes: 1 addition & 1 deletion packages/hooks/src/usePagination/demo/demo4.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const PaginationComponent = () => {
run(
{
current: 1,
pageSize: params[0]?.pageSize,
pageSize: params[0]?.pageSize || 10,
},
gender,
);
Expand Down
2 changes: 1 addition & 1 deletion packages/hooks/src/useReactive/demo/demo2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { useReactive } from 'ahooks';

export default () => {
const state = useReactive({
const state = useReactive<{ arr: number[] }>({
arr: [],
});

Expand Down
24 changes: 0 additions & 24 deletions packages/hooks/src/useRequest/doc/basic/demo/formatResult.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions packages/hooks/src/useRequest/doc/basic/demo/params.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useRequest } from 'ahooks';
import Mock from 'mockjs';
import React, { useState } from 'react';

function getUsername(id: number): Promise<string> {
function getUsername(id: string): Promise<string> {
return new Promise((resolve) => {
setTimeout(() => {
resolve(Mock.mock('@name'));
Expand All @@ -19,7 +19,7 @@ export default () => {
run,
params,
} = useRequest(getUsername, {
defaultParams: [1],
defaultParams: ['1'],
});

const onChange = () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/hooks/src/useSize/demo/demo1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import React, { useRef } from 'react';
import { useSize } from 'ahooks';

export default () => {
const ref = useRef();
const ref = useRef(null);
const size = useSize(ref);
return (
<div ref={ref}>
Expand Down
2 changes: 1 addition & 1 deletion packages/hooks/src/useTextSelection/demo/demo3.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import React, { useRef } from 'react';
import { useTextSelection } from 'ahooks';

export default () => {
const ref = useRef();
const ref = useRef(null);
const selection = useTextSelection(ref);
return (
<div>
Expand Down
4 changes: 2 additions & 2 deletions packages/hooks/src/useVirtualList/demo/demo1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import React, { useMemo, useRef } from 'react';
import { useVirtualList } from 'ahooks';

export default () => {
const containerRef = useRef();
const wrapperRef = useRef();
const containerRef = useRef(null);
const wrapperRef = useRef(null);

const originalList = useMemo(() => Array.from(Array(99999).keys()), []);

Expand Down
4 changes: 2 additions & 2 deletions packages/hooks/src/useVirtualList/demo/demo2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import React, { useMemo, useRef } from 'react';
import { useVirtualList } from 'ahooks';

export default () => {
const containerRef = useRef();
const wrapperRef = useRef();
const containerRef = useRef(null);
const wrapperRef = useRef(null);

const originalList = useMemo(() => Array.from(Array(99999).keys()), []);

Expand Down
Loading

0 comments on commit 258282b

Please sign in to comment.