From e559b37b72e89c8bc1e7bfff6e313d17bc9f775d Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Mon, 17 Oct 2022 18:02:01 +0700 Subject: [PATCH] Update dev dependencies --- package.json | 29 ++++++++++++----------------- source/index.ts | 14 +++++++------- source/types.ts | 16 ++++++++++++---- test/test.ts | 15 +++++++++++---- 4 files changed, 42 insertions(+), 32 deletions(-) diff --git a/package.json b/package.json index 3c029c5..0739ed8 100644 --- a/package.json +++ b/package.json @@ -11,14 +11,16 @@ "url": "https://sindresorhus.com" }, "type": "module", - "exports": "./dist/index.js", - "types": "./dist/index.d.ts", + "exports": { + "types": "./dist/index.d.ts", + "default": "./dist/index.js" + }, "engines": { "node": ">=14.16" }, "scripts": { "build": "del dist && tsc", - "test": "xo && ava", + "test": "tsc --noEmit && xo && ava", "prepare": "npm run build" }, "files": [ @@ -50,17 +52,17 @@ ], "devDependencies": { "@sindresorhus/tsconfig": "^3.0.1", - "@types/jsdom": "^16.2.15", - "@types/node": "^18.0.6", + "@types/jsdom": "^20.0.0", + "@types/node": "^18.11.0", "@types/zen-observable": "^0.8.3", - "ava": "^4.3.1", + "ava": "^4.3.3", "del-cli": "^5.0.0", - "jsdom": "^20.0.0", - "rxjs": "^7.5.6", + "jsdom": "^20.0.1", + "rxjs": "^7.5.7", "tempy": "^3.0.0", "ts-node": "^10.9.1", - "typescript": "~4.7.4", - "xo": "^0.51.0", + "typescript": "~4.8.4", + "xo": "^0.52.4", "zen-observable": "^0.8.15" }, "sideEffects": false, @@ -71,12 +73,5 @@ "nodeArguments": [ "--loader=ts-node/esm" ] - }, - "xo": { - "rules": { - "@typescript-eslint/no-empty-function": "off", - "@typescript-eslint/explicit-function-return-type": "off", - "@typescript-eslint/triple-slash-reference": "off" - } } } diff --git a/source/index.ts b/source/index.ts index e8e6506..1ca92ab 100644 --- a/source/index.ts +++ b/source/index.ts @@ -251,7 +251,7 @@ is.sharedArrayBuffer = isObjectOfType('SharedArrayBuffer'); is.dataView = isObjectOfType('DataView'); -is.enumCase = (value: unknown, targetEnum: T) => Object.values(targetEnum).includes(value as string); +is.enumCase = (value: unknown, targetEnum: T): boolean => Object.values(targetEnum as any).includes(value as string); is.directInstanceOf = (instance: unknown, class_: Class): instance is T => Object.getPrototypeOf(instance) === class_.prototype; @@ -298,10 +298,10 @@ is.plainObject = (value: unknown): value is Record isTypedArrayName(getObjectType(value)); -export interface ArrayLike { +export type ArrayLike = { readonly [index: number]: T; readonly length: number; -} +}; const isValidLength = (value: unknown): value is number => is.safeInteger(value) && value >= 0; is.arrayLike = (value: unknown): value is ArrayLike => !is.nullOrUndefined(value) && !is.function_(value) && isValidLength((value as ArrayLike).length); @@ -354,9 +354,9 @@ is.observable = (value: unknown): value is ObservableLike => { return false; }; -export interface NodeStream extends NodeJS.EventEmitter { +export type NodeStream = { pipe(destination: T, options?: {end?: boolean}): T; -} +} & NodeJS.EventEmitter; is.nodeStream = (value: unknown): value is NodeStream => is.object(value) && is.function_((value as NodeStream).pipe) && !is.observable(value); @@ -490,7 +490,7 @@ export const enum AssertionTypeDescription { } // Type assertions have to be declared with an explicit type. -interface Assert { +type Assert = { // Unknowns. undefined: (value: unknown) => asserts value is undefined; string: (value: unknown) => asserts value is string; @@ -585,7 +585,7 @@ interface Assert { // Variadic functions. any: (predicate: Predicate | Predicate[], ...values: unknown[]) => void | never; all: (predicate: Predicate, ...values: unknown[]) => void | never; -} +}; /* eslint-disable @typescript-eslint/no-confusing-void-expression */ export const assert: Assert = { diff --git a/source/types.ts b/source/types.ts index d49b282..60411b2 100644 --- a/source/types.ts +++ b/source/types.ts @@ -15,6 +15,13 @@ export type Primitive = /** Matches a [`class` constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes). */ +/// type Constructor = new(...arguments_: Arguments) => T; + +/** +Matches a [`class`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes). +*/ +// TODO: Use the below in the next major version. +// export type Class = Constructor & {prototype: T}; export type Class = new (...arguments_: Arguments) => T; /** @@ -34,6 +41,7 @@ export type TypedArray = | BigUint64Array; declare global { + // eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- This must be an `interface` so it can be merged. interface SymbolConstructor { readonly observable: symbol; } @@ -42,15 +50,15 @@ declare global { /** Matches a value that is like an [Observable](https://github.com/tc39/proposal-observable). */ -export interface ObservableLike { +export type ObservableLike = { subscribe(observer: (value: unknown) => void): void; [Symbol.observable](): ObservableLike; -} +}; // eslint-disable-next-line @typescript-eslint/ban-types export type Falsy = false | 0 | 0n | '' | null | undefined; -export interface WeakRef { // eslint-disable-line @typescript-eslint/ban-types +export type WeakRef = { // eslint-disable-line @typescript-eslint/ban-types readonly [Symbol.toStringTag]: 'WeakRef'; deref(): T | undefined; -} +}; diff --git a/test/test.ts b/test/test.ts index 4343fcf..5f57ab9 100644 --- a/test/test.ts +++ b/test/test.ts @@ -1,14 +1,21 @@ +/* eslint-disable @typescript-eslint/no-empty-function */ import {Buffer} from 'node:buffer'; import fs from 'node:fs'; import net from 'node:net'; import Stream from 'node:stream'; import {inspect} from 'node:util'; -import test, {ExecutionContext} from 'ava'; +import test, {type ExecutionContext} from 'ava'; import {JSDOM} from 'jsdom'; import {Subject, Observable} from 'rxjs'; import {temporaryFile} from 'tempy'; import ZenObservable from 'zen-observable'; -import is, {assert, AssertionTypeDescription, Primitive, TypedArray, TypeName} from '../source/index.js'; +import is, { + assert, + AssertionTypeDescription, + type Primitive, + type TypedArray, + type TypeName, +} from '../source/index.js'; class PromiseSubclassFixture extends Promise {} class ErrorSubclassFixture extends Error {} @@ -17,13 +24,13 @@ const {window} = new JSDOM(); const {document} = window; const createDomElement = (element: string) => document.createElement(element); -interface Test { +type Test = { assert: (...args: any[]) => void | never; fixtures: unknown[]; typename?: TypeName; typeDescription?: AssertionTypeDescription | TypeName; is(value: unknown): boolean; -} +}; const invertAssertThrow = (description: string, fn: () => void | never, value: unknown): void | never => { const expectedAssertErrorMessage = `Expected value which is \`${description}\`, received value of type \`${is(value)}\`.`;