Structure fixtures so they can be easily tested for exclusivity (#215)

This commit is contained in:
Bjorn Stromberg 2025-06-06 19:58:46 +08:00 committed by GitHub
parent 882a91c54f
commit ef35cc350a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 425 additions and 733 deletions

View file

@ -11,6 +11,7 @@ import type {
WeakRef,
Whitespace,
} from './types.js';
import {keysOf} from './utilities.js';
// From type-fest.
type ExtractFromGlobalConstructors<Name extends string> =
@ -209,10 +210,14 @@ function detect(value: unknown): TypeName {
}
const tagType = getObjectType(value);
if (tagType) {
if (tagType && tagType !== 'Object') {
return tagType;
}
if (hasPromiseApi(value)) {
return 'Promise';
}
if (value instanceof String || value instanceof Boolean || value instanceof Number) {
throw new TypeError('Please don\'t use object wrappers for primitive types');
}
@ -1120,10 +1125,6 @@ const methodTypeMap = {
isWhitespaceString: 'whitespace string',
} as const;
function keysOf<T extends Record<PropertyKey, unknown>>(value: T): Array<keyof T> {
return Object.keys(value) as Array<keyof T>;
}
type IsMethodName = keyof typeof methodTypeMap;
const isMethodNames: IsMethodName[] = keysOf(methodTypeMap);

3
source/utilities.ts Normal file
View file

@ -0,0 +1,3 @@
export function keysOf<T extends Record<PropertyKey, unknown>>(value: T): Array<keyof T> {
return Object.keys(value) as Array<keyof T>;
}