Skip to content
This repository was archived by the owner on Mar 21, 2025. It is now read-only.

Commit b5ae37a

Browse files
fix: remove all anys
1 parent 57dbcdb commit b5ae37a

26 files changed

Lines changed: 193 additions & 228 deletions

File tree

packages/components/src/atoms/input/Input.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useCallback, useState, useContext } from 'react';
1+
import { useCallback, useState, useContext, ChangeEvent } from 'react';
22
import { ThemeContext } from 'styled-components';
33

44
import { BoxProps } from '../../primal';
@@ -15,7 +15,7 @@ const Input = ({ onChange, type, value, name, ...rest }: Props) => {
1515
const [v, setValue] = useState<string | number | undefined | unknown>(value);
1616

1717
const handleOnChange = useCallback(
18-
(event: any) => {
18+
(event: boolean | ChangeEvent<HTMLInputElement>) => {
1919
if (typeof event !== 'boolean') {
2020
setValue(event.target.value);
2121
} else {

packages/components/src/atoms/input/types.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import { ChangeEvent } from 'react';
2+
13
import type { CheckboxProps } from './checkbox';
24

35
type DefaultProps = {
46
name?: string;
5-
onChange?: (e: any) => void;
7+
onChange?: (e: boolean | ChangeEvent<HTMLInputElement>) => void;
68
};
79

810
type TextInputProps = {
@@ -13,4 +15,4 @@ type TextInputProps = {
1315

1416
export type InputPropsUnion =
1517
| (DefaultProps & TextInputProps)
16-
| (Omit<DefaultProps, 'onChange'> & CheckboxProps & { type: 'checkbox' });
18+
| (DefaultProps & CheckboxProps & { type: 'checkbox' });

packages/memoize/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import areInputsEqual from './are-inputs-equal';
22
import type { EqualityFn, MemoizedFn, Cache } from './types';
33

4-
function index<TFunc extends (this: any, ...newArgs: any[]) => any>(
4+
function index<TFunc extends (this: unknown, ...newArgs: unknown[]) => unknown>(
55
resultFn: TFunc,
66
isEqual: EqualityFn<TFunc> = areInputsEqual
77
): MemoizedFn<TFunc> {

packages/memoize/src/types.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
export type EqualityFn<TFunc extends (...args: any[]) => any> = (
1+
export type EqualityFn<TFunc extends (...args: unknown[]) => unknown> = (
22
newArgs: Parameters<TFunc>,
33
lastArgs: Parameters<TFunc>
44
) => boolean;
55

6-
export type MemoizedFn<TFunc extends (this: any, ...args: any[]) => any> = {
6+
export type MemoizedFn<
7+
TFunc extends (this: unknown, ...args: unknown[]) => unknown
8+
> = {
79
clear: () => void;
810
(
911
this: ThisParameterType<TFunc>,
@@ -12,7 +14,9 @@ export type MemoizedFn<TFunc extends (this: any, ...args: any[]) => any> = {
1214
};
1315

1416
// internal type
15-
export type Cache<TFunc extends (this: any, ...args: any[]) => any> = {
17+
export type Cache<
18+
TFunc extends (this: unknown, ...args: unknown[]) => unknown
19+
> = {
1620
lastThis: ThisParameterType<TFunc>;
1721
lastArgs: Parameters<TFunc>;
1822
lastResult: ReturnType<TFunc>;

packages/memoize/test/memoize-one.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ describe('respecting "this" context', () => {
265265
const Foo = function (this: HasBar, bar: string): void {
266266
this.bar = bar;
267267
};
268-
const memoized = memoize(function (bar) {
268+
const memoized = memoize(function (bar: string) {
269269
return new Foo(bar);
270270
});
271271

packages/memoize/test/types-test.spec.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import memoize from '../src';
66
import type { EqualityFn, MemoizedFn } from '../src';
77

88
it('should maintain the types of the original function', () => {
9-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
10-
function getLocation(this: Window, value: number) {
9+
function getLocation(this: Window) {
1110
return this.location;
1211
}
1312
const memoized = memoize(getLocation);
@@ -47,7 +46,7 @@ it('should return a `MemoizedFn<T>`', () => {
4746
});
4847

4948
it('should allow you to leverage the MemoizedFn generic to allow many memoized functions', () => {
50-
function withDeepEqual<TFunc extends (...args: any[]) => any>(
49+
function withDeepEqual<TFunc extends (...args: unknown[]) => unknown>(
5150
fn: TFunc
5251
): MemoizedFn<TFunc> {
5352
return memoize(fn, isEqual);
@@ -223,49 +222,55 @@ it('should allow weaker equality function types', () => {
223222
expectTypeOf<typeof isEqual>().toMatchTypeOf<EqualityFn<typeof add>>();
224223
}
225224

226-
// ✅ tuple of 'any'
225+
// ✅ tuple of 'unknown'
227226
{
228-
const isEqual = function (first: [any, any], second: [any, any]) {
227+
const isEqual = function (
228+
first: [unknown, unknown],
229+
second: [unknown, unknown]
230+
) {
229231
return true;
230232
};
231233
expectTypeOf<typeof isEqual>().toMatchTypeOf<EqualityFn<typeof add>>();
232234
}
233235

234-
// ❌ tuple of 'any' or incorrect size
236+
// ❌ tuple of 'unknown' or incorrect size
235237
{
236-
const isEqual = function (first: [any, any, any], second: [any, any]) {
238+
const isEqual = function (
239+
first: [unknown, unknown, unknown],
240+
second: [unknown, unknown]
241+
) {
237242
return true;
238243
};
239244
expectTypeOf<typeof isEqual>().not.toMatchTypeOf<EqualityFn<typeof add>>();
240245
}
241246

242-
// ✅ array of 'any'
247+
// ✅ array of 'unknown'
243248
{
244-
const isEqual = function (first: any[], second: any[]) {
249+
const isEqual = function (first: unknown[], second: unknown[]) {
245250
return true;
246251
};
247252
expectTypeOf<typeof isEqual>().toMatchTypeOf<EqualityFn<typeof add>>();
248253
}
249254

250-
// ✅ two arguments of type any
255+
// ✅ two arguments of type unknown
251256
{
252-
const isEqual = function (first: any, second: any) {
257+
const isEqual = function (first: unknown, second: unknown) {
253258
return true;
254259
};
255260
expectTypeOf<typeof isEqual>().toMatchTypeOf<EqualityFn<typeof add>>();
256261
}
257262

258-
// ✅ a single argument of type any
263+
// ✅ a single argument of type unknown
259264
{
260-
const isEqual = function (first: any) {
265+
const isEqual = function (first: unknown) {
261266
return true;
262267
};
263268
expectTypeOf<typeof isEqual>().toMatchTypeOf<EqualityFn<typeof add>>();
264269
}
265270

266-
// ✅ spread of any type
271+
// ✅ spread of unknown type
267272
{
268-
const isEqual = function (...first: any[]) {
273+
const isEqual = function (...first: unknown[]) {
269274
return true;
270275
};
271276
expectTypeOf<typeof isEqual>().toMatchTypeOf<EqualityFn<typeof add>>();

packages/react-lazy-named/src/index.spec.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ import lazy from './';
55

66
const { Suspense } = React;
77

8-
function Text(props) {
9-
return props.text;
8+
interface Props {
9+
text: string;
10+
}
11+
12+
function Text(props: Props) {
13+
return <>{props.text}</>;
1014
}
1115

1216
async function fakeImport(result) {

packages/react-lazy-named/src/index.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,4 @@
1-
/**
2-
* Improvement on top of React.lazy() that allows lazy rendering of named imports
3-
* Usage:
4-
*
5-
* -- alternative to import { primary } from './Button'
6-
* const PrimaryButton = lazier(() => import('./Button'), 'primary');
7-
*
8-
* -- get the default import
9-
* lazier(() => import('./Button'), 'default');
10-
*
11-
* -- or
12-
* lazier(() => import('./Button'));
13-
*
14-
*/
1+
/* eslint @typescript-eslint/no-explicit-any: 0 */
152
import { get } from 'lodash';
163
import * as React from 'react';
174

0 commit comments

Comments
 (0)