Tighten types

This commit is contained in:
Nathan Bierema 2023-01-04 21:38:43 -05:00
parent 1de4f48200
commit 9466c868be
10 changed files with 29 additions and 29 deletions

View File

@ -3,7 +3,7 @@ import JSONArrow from './JSONArrow';
import type { CircularCache, CommonInternalProps } from './types';
interface Props extends CommonInternalProps {
data: any;
data: unknown;
nodeType: string;
from: number;
to: number;

View File

@ -4,14 +4,14 @@ import type { CommonInternalProps } from './types';
// Returns the "n Items" string for this node,
// generating and caching it if it hasn't been created yet.
function createItemString(data: any) {
function createItemString(data: unknown) {
return `${(data as unknown[]).length} ${
(data as unknown[]).length !== 1 ? 'items' : 'item'
}`;
}
interface Props extends CommonInternalProps {
data: any;
data: unknown;
nodeType: string;
}
@ -24,7 +24,7 @@ export default function JSONArrayNode({ data, ...props }: Props) {
nodeType="Array"
nodeTypeIndicator="[]"
createItemString={createItemString}
expandable={data.length > 0}
expandable={(data as unknown[]).length > 0}
/>
);
}

View File

@ -23,7 +23,7 @@ function createItemString(data: any, limit: number) {
}
interface Props extends CommonInternalProps {
data: any;
data: unknown;
nodeType: string;
}

View File

@ -10,7 +10,7 @@ import type { CircularCache, CommonInternalProps } from './types';
*/
export interface RenderChildNodesProps extends CommonInternalProps {
data: any;
data: unknown;
nodeType: string;
circularCache: CircularCache;
level: number;
@ -23,7 +23,7 @@ interface Range {
interface Entry {
key: string | number;
value: any;
value: unknown;
}
function isRange(rangeOrEntry: Range | Entry): rangeOrEntry is Range {
@ -87,10 +87,10 @@ function renderChildNodes(
}
interface Props extends CommonInternalProps {
data: any;
data: unknown;
nodeType: string;
nodeTypeIndicator: string;
createItemString: (data: any, collectionLimit: number) => string;
createItemString: (data: unknown, collectionLimit: number) => string;
expandable: boolean;
}

View File

@ -7,7 +7,7 @@ import JSONValueNode from './JSONValueNode';
import type { CommonInternalProps } from './types';
interface Props extends CommonInternalProps {
value: any;
value: unknown;
}
export default function JSONNode({

View File

@ -4,13 +4,13 @@ import type { CommonInternalProps } from './types';
// Returns the "n Items" string for this node,
// generating and caching it if it hasn't been created yet.
function createItemString(data: any) {
function createItemString(data: unknown) {
const len = Object.getOwnPropertyNames(data).length;
return `${len} ${len !== 1 ? 'keys' : 'key'}`;
}
interface Props extends CommonInternalProps {
data: any;
data: unknown;
nodeType: string;
}

View File

@ -19,9 +19,9 @@ interface Props {
labelRenderer: LabelRenderer;
nodeType: string;
styling: Styling;
value: any;
value: unknown;
valueRenderer: ValueRenderer;
valueGetter?: (value: any) => any;
valueGetter?: (value: any) => unknown;
}
export default function JSONValueNode({

View File

@ -1,6 +1,6 @@
import type { SortObjectKeys } from './types';
function getLength(type: string, collection: any) {
function getLength(type: string, collection: unknown) {
if (type === 'Object') {
// eslint-disable-next-line @typescript-eslint/ban-types
return Object.keys(collection as {}).length;
@ -11,8 +11,8 @@ function getLength(type: string, collection: any) {
return Infinity;
}
function isIterableMap(collection: any) {
return typeof (collection as Map<any, any>).set === 'function';
function isIterableMap(collection: unknown) {
return typeof (collection as Map<unknown, unknown>).set === 'function';
}
function getEntries(
@ -21,7 +21,7 @@ function getEntries(
sortObjectKeys: SortObjectKeys,
from = 0,
to = Infinity
): { entries: { key: string | number; value: any }[]; hasMore?: boolean } {
): { entries: { key: string | number; value: unknown }[]; hasMore?: boolean } {
let res;
if (type === 'Object') {
@ -97,7 +97,7 @@ function getRanges(from: number, to: number, limit: number) {
export default function getCollectionEntries(
type: string,
collection: any,
collection: unknown,
sortObjectKeys: SortObjectKeys,
limit: number,
from = 0,

View File

@ -17,7 +17,7 @@ import type {
} from './types';
interface Props extends Partial<CommonExternalProps> {
data: any;
data: unknown;
theme?: Theme;
invertTheme?: boolean;
}

View File

@ -3,11 +3,11 @@ import { StylingFunction } from 'react-base16-styling';
export type Key = string | number;
export type KeyPath = (string | number)[];
export type KeyPath = readonly (string | number)[];
export type GetItemString = (
nodeType: string,
data: any,
data: unknown,
itemType: React.ReactNode,
itemString: string,
keyPath: KeyPath
@ -21,26 +21,26 @@ export type LabelRenderer = (
) => React.ReactNode;
export type ValueRenderer = (
valueAsString: any,
value: any,
valueAsString: unknown,
value: unknown,
...keyPath: KeyPath
) => React.ReactNode;
export type ShouldExpandNodeInitially = (
keyPath: KeyPath,
data: any,
data: unknown,
level: number
) => boolean;
export type PostprocessValue = (value: any) => any;
export type PostprocessValue = (value: unknown) => unknown;
export type IsCustomNode = (value: any) => boolean;
export type IsCustomNode = (value: unknown) => boolean;
export type SortObjectKeys = ((a: any, b: any) => number) | boolean;
export type SortObjectKeys = ((a: unknown, b: unknown) => number) | boolean;
export type Styling = StylingFunction;
export type CircularCache = any[];
export type CircularCache = unknown[];
export interface CommonExternalProps {
keyPath: KeyPath;