vitest 2.1.3 → 2.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +1 -209
- package/dist/browser.d.ts +24 -24
- package/dist/browser.js +7 -7
- package/dist/chunks/{RandomSequencer.Bh5-tlNJ.js → RandomSequencer.CMRlh2v4.js} +143 -142
- package/dist/chunks/{base.BO5Jx7vw.js → base.BZZh4cSm.js} +3 -3
- package/dist/chunks/{benchmark.C8CRJYG4.js → benchmark.Cdu9hjj4.js} +2 -2
- package/dist/chunks/{benchmark.JVlTzojj.d.ts → benchmark.geERunq4.d.ts} +1 -1
- package/dist/chunks/{cac.BSMVokHR.js → cac.DWAW3Uh5.js} +11 -10
- package/dist/chunks/{cli-api.btGgw3PC.js → cli-api.BtqJwSCh.js} +828 -644
- package/dist/chunks/{config.Crbj2GAb.d.ts → config.Cy0C388Z.d.ts} +0 -1
- package/dist/chunks/{console.CfT1Wjed.js → console.BYGVloWk.js} +2 -6
- package/dist/chunks/{coverage.zlNdAMHK.js → coverage.BoMDb1ip.js} +1 -1
- package/dist/chunks/{creator.CBPphXqR.js → creator.IIqd8RWT.js} +8 -8
- package/dist/chunks/{execute._eQQfgI8.js → execute.2pr0rHgK.js} +8 -6
- package/dist/chunks/{globals.Bdzt04Qm.js → globals.D8ZVAdXd.js} +8 -13
- package/dist/chunks/{index.BpSiYbpB.js → index.68735LiX.js} +28 -5
- package/dist/chunks/{index.X0nbfr6-.js → index.BJDntFik.js} +7 -7
- package/dist/chunks/{index.CPD77dLA.js → index.CqYx2Nsr.js} +7 -7
- package/dist/chunks/{index.Dz2opmmU.js → index.DsZFoqi9.js} +3711 -3788
- package/dist/chunks/{index.lVXYBqEP.js → index.K90BXFOx.js} +186 -186
- package/dist/chunks/index.ckWaX2gY.js +54 -0
- package/dist/chunks/{index.4GFF2h22.js → index.nEwtF0bu.js} +6 -6
- package/dist/chunks/{node.Bx4JZjMG.js → node.AKq966Jp.js} +1 -5
- package/dist/chunks/{reporters.C4ZHgdxQ.d.ts → reporters.D7Jzd9GS.d.ts} +1246 -1221
- package/dist/chunks/{resolveConfig.Dha6ilPI.js → resolveConfig.RxKrDli4.js} +3196 -3176
- package/dist/chunks/{rpc.B7Mfb-Yf.js → rpc.C3q9uwRX.js} +2 -2
- package/dist/chunks/{run-once.Sxe67Wng.js → run-once.2ogXb3JV.js} +1 -1
- package/dist/chunks/{runBaseTests.Cx4wXyTR.js → runBaseTests.3qpJUEJM.js} +21 -25
- package/dist/chunks/{setup-common.BKyF15v_.js → setup-common.Dj6BZI3u.js} +3 -3
- package/dist/chunks/{suite.BMWOKiTe.d.ts → suite.B2jumIFP.d.ts} +2 -2
- package/dist/chunks/utils.C8RiOc4B.js +77 -0
- package/dist/chunks/{utils.CY6Spixo.js → utils.DNoFbBUZ.js} +7 -3
- package/dist/chunks/{vi.BskyZC5g.js → vi.DgezovHB.js} +177 -142
- package/dist/chunks/{vite.YH7MrecS.d.ts → vite.C-N5BBZe.d.ts} +1 -1
- package/dist/chunks/{vm.DB_hLchi.js → vm.Zr4qWzDJ.js} +8 -8
- package/dist/chunks/{worker.CcJLfX8w.d.ts → worker.B9FxPCaC.d.ts} +1 -1
- package/dist/chunks/{worker.B6RjTtbk.d.ts → worker.tN5KGIih.d.ts} +14 -4
- package/dist/cli.js +3 -4
- package/dist/config.cjs +4 -4
- package/dist/config.d.ts +11 -11
- package/dist/config.js +4 -4
- package/dist/coverage.d.ts +10 -10
- package/dist/coverage.js +8 -11
- package/dist/environments.d.ts +2 -2
- package/dist/environments.js +1 -1
- package/dist/execute.d.ts +54 -54
- package/dist/execute.js +7 -6
- package/dist/index.d.ts +106 -1101
- package/dist/index.js +7 -18
- package/dist/node.d.ts +44 -42
- package/dist/node.js +23 -29
- package/dist/path.js +1 -1
- package/dist/reporters.d.ts +10 -10
- package/dist/reporters.js +12 -18
- package/dist/runners.d.ts +12 -19
- package/dist/runners.js +142 -148
- package/dist/snapshot.js +2 -6
- package/dist/suite.d.ts +2 -2
- package/dist/suite.js +2 -6
- package/dist/worker.js +10 -7
- package/dist/workers/forks.js +9 -8
- package/dist/workers/runVmTests.js +16 -20
- package/dist/workers/threads.js +9 -8
- package/dist/workers/vmForks.js +9 -12
- package/dist/workers/vmThreads.js +9 -12
- package/dist/workers.d.ts +14 -14
- package/dist/workers.js +15 -18
- package/package.json +27 -27
- package/dist/chunks/base.DwXGwWst.js +0 -89
- package/dist/chunks/env.CmHVDJnw.js +0 -7
- package/dist/chunks/index.-d_XpZEA.js +0 -140
- package/dist/chunks/index.CxRxs566.js +0 -23
- package/dist/chunks/tasks.BZnCS9aT.js +0 -18
- package/dist/chunks/utils.Ck2hJTRs.js +0 -23
- package/dist/chunks/{environment.CzISCQ7o.d.ts → environment.LoooBwUu.d.ts} +24 -24
package/dist/index.d.ts
CHANGED
|
@@ -1,41 +1,42 @@
|
|
|
1
|
-
import '
|
|
1
|
+
import { TaskResultPack as TaskResultPack$1, File as File$1, TaskPopulated, Suite as Suite$1, Test as Test$1, Custom as Custom$1, Task as Task$1, TaskBase as TaskBase$1, TaskResult as TaskResult$1, DoneCallback as DoneCallback$1, RuntimeContext as RuntimeContext$1, SuiteHooks as SuiteHooks$1, SequenceHooks as SequenceHooks$1, SequenceSetupFiles as SequenceSetupFiles$1 } from '@vitest/runner';
|
|
2
|
+
export { CancelReason, ExtendedContext, HookCleanupCallback, HookListener, OnTestFailedHandler, OnTestFinishedHandler, RunMode, Custom as RunnerCustomCase, Task as RunnerTask, TaskBase as RunnerTaskBase, TaskResult as RunnerTaskResult, TaskResultPack as RunnerTaskResultPack, Test as RunnerTestCase, File as RunnerTestFile, Suite as RunnerTestSuite, SuiteAPI, SuiteCollector, SuiteFactory, TaskContext, TaskCustomOptions, TaskMeta, TaskState, TestAPI, TestContext, TestFunction, TestOptions, afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, onTestFinished, suite, test } from '@vitest/runner';
|
|
3
|
+
import { f as VitestEnvironment$1, S as SerializedTestSpecification, g as RawErrsMap$1, T as TscErrorInfo$1, h as CollectLineNumbers$1, i as CollectLines$1, j as RootAndTarget$1, k as Context$1, C as CoverageProvider$1, a as ReportContext$1, b as CoverageProviderModule$1, l as CoverageReporter$1, m as CoverageProviderName, n as CoverageOptions$1, R as ResolvedCoverageOptions$1, B as BaseCoverageOptions$1, o as CoverageIstanbulOptions$1, c as CoverageV8Options$1, p as CustomProviderOptions$1, q as Reporter$1, V as Vitest$1, r as BrowserScript$1, s as BrowserConfigOptions$1, t as BuiltinEnvironment$1, P as Pool$1, u as PoolOptions$1, v as CSSModuleScopeStrategy$1, A as ApiConfig$1, w as VitestRunMode$1, D as DepsOptimizationOptions$1, x as TransformModePatterns$1, I as InlineConfig$1, y as TypecheckConfig$1, z as UserConfig$1, E as ResolvedConfig$1, F as ProjectConfig$1, U as UserWorkspaceConfig$1, G as BenchmarkUserOptions$1 } from './chunks/reporters.D7Jzd9GS.js';
|
|
4
|
+
import { W as WorkerContext$1 } from './chunks/worker.B9FxPCaC.js';
|
|
5
|
+
import { U as UserConsoleLog, M as ModuleGraphData, b as Awaitable$1, P as ProvidedContext, N as Nullable$1, c as Arrayable$1, d as ArgumentsType$1, e as MutableArray$1, C as Constructable$1, O as OnServerRestartHandler$1, a as EnvironmentReturn$1, V as VmEnvironmentReturn$1, E as Environment$1, R as ResolvedTestEnvironment$1, J as JSDOMOptions$1, H as HappyDOMOptions$1, f as EnvironmentOptions$1 } from './chunks/environment.LoooBwUu.js';
|
|
6
|
+
export { A as AfterSuiteRunMeta, g as ModuleCache } from './chunks/environment.LoooBwUu.js';
|
|
7
|
+
import { a as BirpcReturn, b as WorkerRPC$1 } from './chunks/worker.tN5KGIih.js';
|
|
8
|
+
export { C as ContextRPC, d as ContextTestEnvironment, e as ResolveIdFunction, c as RunnerRPC, R as RuntimeRPC, W as WorkerGlobalState } from './chunks/worker.tN5KGIih.js';
|
|
9
|
+
import './chunks/vite.C-N5BBZe.js';
|
|
10
|
+
import { PromisifyAssertion, Tester, ExpectStatic } from '@vitest/expect';
|
|
11
|
+
export { Assertion, AsymmetricMatchersContaining, ExpectPollOptions, ExpectStatic, JestAssertion } from '@vitest/expect';
|
|
2
12
|
import { Plugin } from '@vitest/pretty-format';
|
|
3
13
|
import { SnapshotState } from '@vitest/snapshot';
|
|
4
14
|
export { SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotSerializer, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, UncheckedSnapshot } from '@vitest/snapshot';
|
|
5
|
-
import {
|
|
6
|
-
export {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
export { b as BenchFunction, a as Benchmark, c as BenchmarkAPI } from './chunks/benchmark.JVlTzojj.js';
|
|
10
|
-
import { U as UserConsoleLog, P as ProvidedContext, M as ModuleGraphData, b as Awaitable$1, N as Nullable$1, c as Arrayable$1, d as ArgumentsType$1, e as MutableArray$1, C as Constructable$1, O as OnServerRestartHandler$1, a as EnvironmentReturn$1, V as VmEnvironmentReturn$1, E as Environment$1, R as ResolvedTestEnvironment$1, J as JSDOMOptions$1, H as HappyDOMOptions$1, f as EnvironmentOptions$1 } from './chunks/environment.CzISCQ7o.js';
|
|
11
|
-
export { A as AfterSuiteRunMeta, g as ModuleCache } from './chunks/environment.CzISCQ7o.js';
|
|
12
|
-
import { TaskPopulated, TaskResultPack as TaskResultPack$1, File as File$1, Suite as Suite$1, Test as Test$1, Custom as Custom$1, Task as Task$1, TaskBase as TaskBase$1, TaskResult as TaskResult$1, DoneCallback as DoneCallback$1, RuntimeContext as RuntimeContext$1, SuiteHooks as SuiteHooks$1, SequenceHooks as SequenceHooks$1, SequenceSetupFiles as SequenceSetupFiles$1 } from '@vitest/runner';
|
|
13
|
-
export { CancelReason, ExtendedContext, HookCleanupCallback, HookListener, OnTestFailedHandler, OnTestFinishedHandler, RunMode, Custom as RunnerCustomCase, Task as RunnerTask, TaskBase as RunnerTaskBase, TaskResult as RunnerTaskResult, TaskResultPack as RunnerTaskResultPack, Test as RunnerTestCase, File as RunnerTestFile, Suite as RunnerTestSuite, SuiteAPI, SuiteCollector, SuiteFactory, TaskContext, TaskCustomOptions, TaskMeta, TaskState, TestAPI, TestContext, TestFunction, TestOptions, afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, onTestFinished, suite, test } from '@vitest/runner';
|
|
14
|
-
import { a as BirpcReturn, b as WorkerRPC$1 } from './chunks/worker.B6RjTtbk.js';
|
|
15
|
-
export { C as ContextRPC, e as ContextTestEnvironment, d as ResolveIdFunction, c as RunnerRPC, R as RuntimeRPC, W as WorkerGlobalState } from './chunks/worker.B6RjTtbk.js';
|
|
16
|
-
import { W as WorkerContext$1 } from './chunks/worker.CcJLfX8w.js';
|
|
17
|
-
export { b as bench } from './chunks/suite.BMWOKiTe.js';
|
|
18
|
-
import { F as FakeTimerInstallOpts, R as RuntimeOptions, S as SerializedConfig } from './chunks/config.Crbj2GAb.js';
|
|
19
|
-
export { b as RuntimeConfig, a as SerializedCoverageConfig } from './chunks/config.Crbj2GAb.js';
|
|
20
|
-
import { M as MockFactoryWithHelper, a as MockOptions } from './chunks/mocker.cRtM890J.js';
|
|
15
|
+
import { B as BenchmarkResult } from './chunks/benchmark.geERunq4.js';
|
|
16
|
+
export { a as BenchFunction, b as Benchmark, c as BenchmarkAPI } from './chunks/benchmark.geERunq4.js';
|
|
17
|
+
import { S as SerializedConfig, F as FakeTimerInstallOpts, R as RuntimeOptions } from './chunks/config.Cy0C388Z.js';
|
|
18
|
+
export { b as RuntimeConfig, a as SerializedCoverageConfig } from './chunks/config.Cy0C388Z.js';
|
|
21
19
|
import { spyOn, fn, MaybeMockedDeep, MaybeMocked, MaybePartiallyMocked, MaybePartiallyMockedDeep, MockInstance } from '@vitest/spy';
|
|
22
20
|
export { Mock, MockContext, MockInstance, Mocked, MockedClass, MockedFunction, MockedObject } from '@vitest/spy';
|
|
21
|
+
import { M as MockFactoryWithHelper, a as MockOptions } from './chunks/mocker.cRtM890J.js';
|
|
22
|
+
export { b as bench } from './chunks/suite.B2jumIFP.js';
|
|
23
|
+
export { ExpectTypeOf, expectTypeOf } from 'expect-type';
|
|
23
24
|
export { ErrorWithDiff, ParsedStack, SerializedError, TestError } from '@vitest/utils';
|
|
24
25
|
export { DiffOptions } from '@vitest/utils/diff';
|
|
25
26
|
import * as chai from 'chai';
|
|
26
27
|
export { chai };
|
|
27
28
|
export { assert, should } from 'chai';
|
|
28
29
|
export { Bench as BenchFactory, Options as BenchOptions, Task as BenchTask, TaskResult as BenchTaskResult } from 'tinybench';
|
|
30
|
+
import 'node:stream';
|
|
29
31
|
import 'vite';
|
|
30
32
|
import 'vite-node';
|
|
31
|
-
import '
|
|
33
|
+
import '@vitest/utils/source-map';
|
|
32
34
|
import 'vite-node/client';
|
|
33
|
-
import '@vitest/snapshot/manager';
|
|
34
35
|
import 'vite-node/server';
|
|
35
|
-
import '@vitest/
|
|
36
|
+
import '@vitest/snapshot/manager';
|
|
36
37
|
import 'node:fs';
|
|
37
|
-
import '@vitest/runner/utils';
|
|
38
38
|
import 'node:worker_threads';
|
|
39
|
+
import '@vitest/runner/utils';
|
|
39
40
|
import '@vitest/snapshot/environment';
|
|
40
41
|
import '@vitest/mocker';
|
|
41
42
|
|
|
@@ -84,8 +85,37 @@ declare module '@vitest/expect' {
|
|
|
84
85
|
matchSnapshot: SnapshotMatcher<T>;
|
|
85
86
|
toMatchSnapshot: SnapshotMatcher<T>;
|
|
86
87
|
toMatchInlineSnapshot: InlineSnapshotMatcher<T>;
|
|
88
|
+
/**
|
|
89
|
+
* Checks that an error thrown by a function matches a previously recorded snapshot.
|
|
90
|
+
*
|
|
91
|
+
* @param message - Optional custom error message.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* expect(functionWithError).toThrowErrorMatchingSnapshot();
|
|
95
|
+
*/
|
|
87
96
|
toThrowErrorMatchingSnapshot: (message?: string) => void;
|
|
97
|
+
/**
|
|
98
|
+
* Checks that an error thrown by a function matches an inline snapshot within the test file.
|
|
99
|
+
* Useful for keeping snapshots close to the test code.
|
|
100
|
+
*
|
|
101
|
+
* @param snapshot - Optional inline snapshot string to match.
|
|
102
|
+
* @param message - Optional custom error message.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* const throwError = () => { throw new Error('Error occurred') };
|
|
106
|
+
* expect(throwError).toThrowErrorMatchingInlineSnapshot(`"Error occurred"`);
|
|
107
|
+
*/
|
|
88
108
|
toThrowErrorMatchingInlineSnapshot: (snapshot?: string, message?: string) => void;
|
|
109
|
+
/**
|
|
110
|
+
* Compares the received value to a snapshot saved in a specified file.
|
|
111
|
+
* Useful for cases where snapshot content is large or needs to be shared across tests.
|
|
112
|
+
*
|
|
113
|
+
* @param filepath - Path to the snapshot file.
|
|
114
|
+
* @param message - Optional custom error message.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* await expect(largeData).toMatchFileSnapshot('path/to/snapshot.json');
|
|
118
|
+
*/
|
|
89
119
|
toMatchFileSnapshot: (filepath: string, message?: string) => Promise<void>;
|
|
90
120
|
}
|
|
91
121
|
}
|
|
@@ -110,1035 +140,59 @@ declare module '@vitest/runner' {
|
|
|
110
140
|
}
|
|
111
141
|
}
|
|
112
142
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
* Represents an equality type that returns {@linkcode Right} if
|
|
123
|
-
* {@linkcode Left} is `true`,
|
|
124
|
-
* otherwise returns the negation of {@linkcode Right}.
|
|
125
|
-
*/
|
|
126
|
-
declare type Eq<Left extends boolean, Right extends boolean> = Left extends true ? Right : Not<Right>;
|
|
127
|
-
declare const secret: unique symbol;
|
|
128
|
-
declare type Secret = typeof secret;
|
|
129
|
-
/**
|
|
130
|
-
* Checks if the given type is `never`.
|
|
131
|
-
*/
|
|
132
|
-
declare type IsNever<T> = [T] extends [never] ? true : false;
|
|
133
|
-
/**
|
|
134
|
-
* Checks if the given type is `any`.
|
|
135
|
-
*/
|
|
136
|
-
declare type IsAny<T> = [T] extends [Secret] ? Not<IsNever<T>> : false;
|
|
137
|
-
/**
|
|
138
|
-
* Determines if the given type is `unknown`.
|
|
139
|
-
*/
|
|
140
|
-
declare type IsUnknown<T> = [unknown] extends [T] ? Not<IsAny<T>> : false;
|
|
141
|
-
/**
|
|
142
|
-
* Determines the printable type representation for a given type.
|
|
143
|
-
*/
|
|
144
|
-
declare type PrintType<T> = IsUnknown<T> extends true ? 'unknown' : IsNever<T> extends true ? 'never' : IsAny<T> extends true ? never : boolean extends T ? 'boolean' : T extends boolean ? `literal boolean: ${T}` : string extends T ? 'string' : T extends string ? `literal string: ${T}` : number extends T ? 'number' : T extends number ? `literal number: ${T}` : T extends null ? 'null' : T extends undefined ? 'undefined' : T extends (...args: any[]) => any ? 'function' : '...';
|
|
145
|
-
/**
|
|
146
|
-
* Subjective "useful" keys from a type. For objects it's just `keyof` but for
|
|
147
|
-
* tuples/arrays it's the number keys.
|
|
148
|
-
*
|
|
149
|
-
* @example
|
|
150
|
-
* ```ts
|
|
151
|
-
* UsefulKeys<{a: 1; b: 2}> // 'a' | 'b'
|
|
152
|
-
*
|
|
153
|
-
* UsefulKeys<['a', 'b']> // '0' | '1'
|
|
154
|
-
*
|
|
155
|
-
* UsefulKeys<string[]> // number
|
|
156
|
-
* ```
|
|
157
|
-
*/
|
|
158
|
-
declare type UsefulKeys<T> = T extends any[] ? {
|
|
159
|
-
[K in keyof T]: K;
|
|
160
|
-
}[number] : keyof T;
|
|
161
|
-
declare type MismatchInfo<Actual, Expected> = And<[Extends<PrintType<Actual>, '...'>, Not<IsAny<Actual>>]> extends true ? And<[Extends<any[], Actual>, Extends<any[], Expected>]> extends true ? Array<MismatchInfo<Extract<Actual, any[]>[number], Extract<Expected, any[]>[number]>> : {
|
|
162
|
-
[K in UsefulKeys<Actual> | UsefulKeys<Expected>]: MismatchInfo<K extends keyof Actual ? Actual[K] : never, K extends keyof Expected ? Expected[K] : never>;
|
|
163
|
-
} : StrictEqualUsingBranding<Actual, Expected> extends true ? Actual : `Expected: ${PrintType<Expected>}, Actual: ${PrintType<Exclude<Actual, Expected>>}`;
|
|
164
|
-
/**
|
|
165
|
-
* Represents a deeply branded type.
|
|
166
|
-
*
|
|
167
|
-
* Recursively walk a type and replace it with a branded type related to the
|
|
168
|
-
* original. This is useful for equality-checking stricter than
|
|
169
|
-
* `A extends B ? B extends A ? true : false : false`, because it detects the
|
|
170
|
-
* difference between a few edge-case types that vanilla typescript
|
|
171
|
-
* doesn't by default:
|
|
172
|
-
* - `any` vs `unknown`
|
|
173
|
-
* - `{ readonly a: string }` vs `{ a: string }`
|
|
174
|
-
* - `{ a?: string }` vs `{ a: string | undefined }`
|
|
175
|
-
*
|
|
176
|
-
* __Note__: not very performant for complex types - this should only be used
|
|
177
|
-
* when you know you need it. If doing an equality check, it's almost always
|
|
178
|
-
* better to use {@linkcode StrictEqualUsingTSInternalIdenticalToOperator}.
|
|
179
|
-
*/
|
|
180
|
-
declare type DeepBrand<T> = IsNever<T> extends true ? {
|
|
181
|
-
type: 'never';
|
|
182
|
-
} : IsAny<T> extends true ? {
|
|
183
|
-
type: 'any';
|
|
184
|
-
} : IsUnknown<T> extends true ? {
|
|
185
|
-
type: 'unknown';
|
|
186
|
-
} : T extends string | number | boolean | symbol | bigint | null | undefined | void ? {
|
|
187
|
-
type: 'primitive';
|
|
188
|
-
value: T;
|
|
189
|
-
} : T extends new (...args: any[]) => any ? {
|
|
190
|
-
type: 'constructor';
|
|
191
|
-
params: ConstructorParams<T>;
|
|
192
|
-
instance: DeepBrand<InstanceType<Extract<T, new (...args: any) => any>>>;
|
|
193
|
-
} : T extends (...args: infer P) => infer R ? {
|
|
194
|
-
type: 'function';
|
|
195
|
-
params: DeepBrand<P>;
|
|
196
|
-
return: DeepBrand<R>;
|
|
197
|
-
this: DeepBrand<ThisParameterType<T>>;
|
|
198
|
-
props: DeepBrand<Omit<T, keyof Function>>;
|
|
199
|
-
} : T extends any[] ? {
|
|
200
|
-
type: 'array';
|
|
201
|
-
items: {
|
|
202
|
-
[K in keyof T]: T[K];
|
|
203
|
-
};
|
|
204
|
-
} : {
|
|
205
|
-
type: 'object';
|
|
206
|
-
properties: {
|
|
207
|
-
[K in keyof T]: DeepBrand<T[K]>;
|
|
208
|
-
};
|
|
209
|
-
readonly: ReadonlyKeys<T>;
|
|
210
|
-
required: RequiredKeys<T>;
|
|
211
|
-
optional: OptionalKeys<T>;
|
|
212
|
-
constructorParams: DeepBrand<ConstructorParams<T>>;
|
|
213
|
-
};
|
|
214
|
-
/**
|
|
215
|
-
* Extracts the keys from a type that are required (not optional).
|
|
216
|
-
*/
|
|
217
|
-
declare type RequiredKeys<T> = Extract<{
|
|
218
|
-
[K in keyof T]-?: {} extends Pick<T, K> ? never : K;
|
|
219
|
-
}[keyof T], keyof T>;
|
|
220
|
-
/**
|
|
221
|
-
* Gets the keys of an object type that are optional.
|
|
222
|
-
*/
|
|
223
|
-
declare type OptionalKeys<T> = Exclude<keyof T, RequiredKeys<T>>;
|
|
224
|
-
/**
|
|
225
|
-
* Extracts the keys from a type that are not readonly.
|
|
226
|
-
*/
|
|
227
|
-
declare type ReadonlyKeys<T> = Extract<{
|
|
228
|
-
[K in keyof T]-?: ReadonlyEquivalent<{
|
|
229
|
-
[_K in K]: T[K];
|
|
230
|
-
}, {
|
|
231
|
-
-readonly [_K in K]: T[K];
|
|
232
|
-
}> extends true ? never : K;
|
|
233
|
-
}[keyof T], keyof T>;
|
|
234
|
-
/**
|
|
235
|
-
* Determines if two types, are equivalent in a `readonly` manner.
|
|
236
|
-
*/
|
|
237
|
-
declare type ReadonlyEquivalent<X, Y> = Extends<(<T>() => T extends X ? true : false), (<T>() => T extends Y ? true : false)>;
|
|
238
|
-
/**
|
|
239
|
-
* Checks if one type extends another.
|
|
240
|
-
*/
|
|
241
|
-
declare type Extends<L, R> = IsNever<L> extends true ? IsNever<R> : [L] extends [R] ? true : false;
|
|
242
|
-
declare type ExtendsUsingBranding<L, R> = Extends<DeepBrand<L>, DeepBrand<R>>;
|
|
243
|
-
declare type ExtendsExcludingAnyOrNever<L, R> = IsAny<L> extends true ? IsAny<R> : Extends<L, R>;
|
|
244
|
-
/**
|
|
245
|
-
* Checks if two types are strictly equal using
|
|
246
|
-
* the TypeScript internal identical-to operator.
|
|
247
|
-
*
|
|
248
|
-
* @see {@link https://github.com/microsoft/TypeScript/issues/55188#issuecomment-1656328122 much history}
|
|
249
|
-
*/
|
|
250
|
-
declare type StrictEqualUsingTSInternalIdenticalToOperator<L, R> = (<T>() => T extends (L & T) | T ? true : false) extends <T>() => T extends (R & T) | T ? true : false ? IsNever<L> extends IsNever<R> ? true : false : false;
|
|
251
|
-
/**
|
|
252
|
-
* Checks if two types are strictly equal using branding.
|
|
253
|
-
*/
|
|
254
|
-
declare type StrictEqualUsingBranding<Left, Right> = And<[
|
|
255
|
-
ExtendsUsingBranding<Left, Right>,
|
|
256
|
-
ExtendsUsingBranding<Right, Left>
|
|
257
|
-
]>;
|
|
258
|
-
/**
|
|
259
|
-
* Extracts the parameter types from a function type.
|
|
260
|
-
*/
|
|
261
|
-
declare type Params<Actual> = Actual extends (...args: infer ParameterTypes) => any ? ParameterTypes : never;
|
|
262
|
-
/**
|
|
263
|
-
* Represents the constructor parameters of a class or constructor function.
|
|
264
|
-
* If the constructor takes no arguments, an empty array is returned.
|
|
265
|
-
*/
|
|
266
|
-
declare type ConstructorParams<Actual> = Actual extends new (...args: infer P) => any ? Actual extends new () => any ? P | [] : P : never;
|
|
267
|
-
declare const mismatch: unique symbol;
|
|
268
|
-
declare type Mismatch = {
|
|
269
|
-
[mismatch]: 'mismatch';
|
|
270
|
-
};
|
|
271
|
-
/**
|
|
272
|
-
* A type which should match anything passed as a value but *doesn't*
|
|
273
|
-
* match {@linkcode Mismatch}. It helps TypeScript select the right overload
|
|
274
|
-
* for {@linkcode PositiveExpectTypeOf.toEqualTypeOf `.toEqualTypeOf()`} and
|
|
275
|
-
* {@linkcode PositiveExpectTypeOf.toMatchTypeOf `.toMatchTypeOf()`}.
|
|
276
|
-
*/
|
|
277
|
-
declare const avalue: unique symbol;
|
|
278
|
-
/**
|
|
279
|
-
* Represents a value that can be of various types.
|
|
280
|
-
*/
|
|
281
|
-
declare type AValue = {
|
|
282
|
-
[avalue]?: undefined;
|
|
283
|
-
} | string | number | boolean | symbol | bigint | null | undefined | void;
|
|
284
|
-
/**
|
|
285
|
-
* Represents the type of mismatched arguments between
|
|
286
|
-
* the actual result and the expected result.
|
|
287
|
-
*
|
|
288
|
-
* If {@linkcode ActualResult} and {@linkcode ExpectedResult} are equivalent,
|
|
289
|
-
* the type resolves to an empty tuple `[]`, indicating no mismatch.
|
|
290
|
-
* If they are not equivalent, it resolves to a tuple containing the element
|
|
291
|
-
* {@linkcode Mismatch}, signifying a discrepancy between
|
|
292
|
-
* the expected and actual results.
|
|
293
|
-
*/
|
|
294
|
-
declare type MismatchArgs<ActualResult extends boolean, ExpectedResult extends boolean> = Eq<ActualResult, ExpectedResult> extends true ? [] : [Mismatch];
|
|
295
|
-
declare const inverted: unique symbol;
|
|
296
|
-
declare type Inverted<T> = {
|
|
297
|
-
[inverted]: T;
|
|
298
|
-
};
|
|
299
|
-
declare const expectNull: unique symbol;
|
|
300
|
-
declare type ExpectNull<T> = {
|
|
301
|
-
[expectNull]: T;
|
|
302
|
-
result: ExtendsExcludingAnyOrNever<T, null>;
|
|
303
|
-
};
|
|
304
|
-
declare const expectUndefined: unique symbol;
|
|
305
|
-
declare type ExpectUndefined<T> = {
|
|
306
|
-
[expectUndefined]: T;
|
|
307
|
-
result: ExtendsExcludingAnyOrNever<T, undefined>;
|
|
308
|
-
};
|
|
309
|
-
declare const expectNumber: unique symbol;
|
|
310
|
-
declare type ExpectNumber<T> = {
|
|
311
|
-
[expectNumber]: T;
|
|
312
|
-
result: ExtendsExcludingAnyOrNever<T, number>;
|
|
313
|
-
};
|
|
314
|
-
declare const expectString: unique symbol;
|
|
315
|
-
declare type ExpectString<T> = {
|
|
316
|
-
[expectString]: T;
|
|
317
|
-
result: ExtendsExcludingAnyOrNever<T, string>;
|
|
318
|
-
};
|
|
319
|
-
declare const expectBoolean: unique symbol;
|
|
320
|
-
declare type ExpectBoolean<T> = {
|
|
321
|
-
[expectBoolean]: T;
|
|
322
|
-
result: ExtendsExcludingAnyOrNever<T, boolean>;
|
|
323
|
-
};
|
|
324
|
-
declare const expectVoid: unique symbol;
|
|
325
|
-
declare type ExpectVoid<T> = {
|
|
326
|
-
[expectVoid]: T;
|
|
327
|
-
result: ExtendsExcludingAnyOrNever<T, void>;
|
|
328
|
-
};
|
|
329
|
-
declare const expectFunction: unique symbol;
|
|
330
|
-
declare type ExpectFunction<T> = {
|
|
331
|
-
[expectFunction]: T;
|
|
332
|
-
result: ExtendsExcludingAnyOrNever<T, (...args: any[]) => any>;
|
|
333
|
-
};
|
|
334
|
-
declare const expectObject: unique symbol;
|
|
335
|
-
declare type ExpectObject<T> = {
|
|
336
|
-
[expectObject]: T;
|
|
337
|
-
result: ExtendsExcludingAnyOrNever<T, object>;
|
|
338
|
-
};
|
|
339
|
-
declare const expectArray: unique symbol;
|
|
340
|
-
declare type ExpectArray<T> = {
|
|
341
|
-
[expectArray]: T;
|
|
342
|
-
result: ExtendsExcludingAnyOrNever<T, any[]>;
|
|
343
|
-
};
|
|
344
|
-
declare const expectSymbol: unique symbol;
|
|
345
|
-
declare type ExpectSymbol<T> = {
|
|
346
|
-
[expectSymbol]: T;
|
|
347
|
-
result: ExtendsExcludingAnyOrNever<T, symbol>;
|
|
348
|
-
};
|
|
349
|
-
declare const expectAny: unique symbol;
|
|
350
|
-
declare type ExpectAny<T> = {
|
|
351
|
-
[expectAny]: T;
|
|
352
|
-
result: IsAny<T>;
|
|
353
|
-
};
|
|
354
|
-
declare const expectUnknown: unique symbol;
|
|
355
|
-
declare type ExpectUnknown<T> = {
|
|
356
|
-
[expectUnknown]: T;
|
|
357
|
-
result: IsUnknown<T>;
|
|
358
|
-
};
|
|
359
|
-
declare const expectNever: unique symbol;
|
|
360
|
-
declare type ExpectNever<T> = {
|
|
361
|
-
[expectNever]: T;
|
|
362
|
-
result: IsNever<T>;
|
|
363
|
-
};
|
|
364
|
-
declare const expectNullable: unique symbol;
|
|
365
|
-
declare type ExpectNullable<T> = {
|
|
366
|
-
[expectNullable]: T;
|
|
367
|
-
result: Not<StrictEqualUsingBranding<T, NonNullable<T>>>;
|
|
368
|
-
};
|
|
369
|
-
/**
|
|
370
|
-
* Represents a scolder function that checks if the result of an expecter
|
|
371
|
-
* matches the specified options.
|
|
372
|
-
*/
|
|
373
|
-
declare type Scolder<Expecter extends {
|
|
374
|
-
result: boolean;
|
|
375
|
-
}, Options extends {
|
|
376
|
-
positive: boolean;
|
|
377
|
-
}> = Expecter['result'] extends Options['positive'] ? () => true : Options['positive'] extends true ? Expecter : Inverted<Expecter>;
|
|
378
|
-
/**
|
|
379
|
-
* Represents the positive assertion methods available for type checking in the
|
|
380
|
-
* {@linkcode expectTypeOf()} utility.
|
|
381
|
-
*/
|
|
382
|
-
interface PositiveExpectTypeOf<Actual> extends BaseExpectTypeOf<Actual, {
|
|
383
|
-
positive: true;
|
|
384
|
-
branded: false;
|
|
385
|
-
}> {
|
|
386
|
-
toEqualTypeOf: {
|
|
387
|
-
/**
|
|
388
|
-
* Uses TypeScript's internal technique to check for type "identicalness".
|
|
389
|
-
*
|
|
390
|
-
* It will check if the types are fully equal to each other.
|
|
391
|
-
* It will not fail if two objects have different values, but the same type.
|
|
392
|
-
* It will fail however if an object is missing a property.
|
|
393
|
-
*
|
|
394
|
-
* **_Unexpected failure_**? For a more permissive but less performant
|
|
395
|
-
* check that accommodates for equivalent intersection types,
|
|
396
|
-
* use {@linkcode branded `.branded.toEqualTypeOf()`}.
|
|
397
|
-
* @see {@link https://github.com/mmkal/expect-type#why-is-my-assertion-failing The documentation for details}.
|
|
398
|
-
*
|
|
399
|
-
* @example
|
|
400
|
-
* <caption>Using generic type argument syntax</caption>
|
|
401
|
-
* ```ts
|
|
402
|
-
* expectTypeOf({ a: 1 }).toEqualTypeOf<{ a: number }>()
|
|
403
|
-
*
|
|
404
|
-
* expectTypeOf({ a: 1, b: 1 }).not.toEqualTypeOf<{ a: number }>()
|
|
405
|
-
* ```
|
|
406
|
-
*
|
|
407
|
-
* @example
|
|
408
|
-
* <caption>Using inferred type syntax by passing a value</caption>
|
|
409
|
-
* ```ts
|
|
410
|
-
* expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 1 })
|
|
411
|
-
*
|
|
412
|
-
* expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 2 })
|
|
413
|
-
* ```
|
|
414
|
-
*
|
|
415
|
-
* @param value - The value to compare against the expected type.
|
|
416
|
-
* @param MISMATCH - The mismatch arguments.
|
|
417
|
-
* @returns `true`.
|
|
418
|
-
*/
|
|
419
|
-
<Expected extends StrictEqualUsingTSInternalIdenticalToOperator<Actual, Expected> extends true ? unknown : MismatchInfo<Actual, Expected>>(value: Expected & AValue, // reason for `& AValue`: make sure this is only the selected overload when the end-user passes a value for an inferred typearg. The `Mismatch` type does match `AValue`.
|
|
420
|
-
...MISMATCH: MismatchArgs<StrictEqualUsingTSInternalIdenticalToOperator<Actual, Expected>, true>): true;
|
|
421
|
-
/**
|
|
422
|
-
* Uses TypeScript's internal technique to check for type "identicalness".
|
|
423
|
-
*
|
|
424
|
-
* It will check if the types are fully equal to each other.
|
|
425
|
-
* It will not fail if two objects have different values, but the same type.
|
|
426
|
-
* It will fail however if an object is missing a property.
|
|
427
|
-
*
|
|
428
|
-
* **_Unexpected failure_**? For a more permissive but less performant
|
|
429
|
-
* check that accommodates for equivalent intersection types,
|
|
430
|
-
* use {@linkcode branded `.branded.toEqualTypeOf()`}.
|
|
431
|
-
* @see {@link https://github.com/mmkal/expect-type#why-is-my-assertion-failing The documentation for details}.
|
|
432
|
-
*
|
|
433
|
-
* @example
|
|
434
|
-
* <caption>Using generic type argument syntax</caption>
|
|
435
|
-
* ```ts
|
|
436
|
-
* expectTypeOf({ a: 1 }).toEqualTypeOf<{ a: number }>()
|
|
437
|
-
*
|
|
438
|
-
* expectTypeOf({ a: 1, b: 1 }).not.toEqualTypeOf<{ a: number }>()
|
|
439
|
-
* ```
|
|
440
|
-
*
|
|
441
|
-
* @example
|
|
442
|
-
* <caption>Using inferred type syntax by passing a value</caption>
|
|
443
|
-
* ```ts
|
|
444
|
-
* expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 1 })
|
|
445
|
-
*
|
|
446
|
-
* expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 2 })
|
|
447
|
-
* ```
|
|
448
|
-
*
|
|
449
|
-
* @param MISMATCH - The mismatch arguments.
|
|
450
|
-
* @returns `true`.
|
|
451
|
-
*/
|
|
452
|
-
<Expected extends StrictEqualUsingTSInternalIdenticalToOperator<Actual, Expected> extends true ? unknown : MismatchInfo<Actual, Expected>>(...MISMATCH: MismatchArgs<StrictEqualUsingTSInternalIdenticalToOperator<Actual, Expected>, true>): true;
|
|
453
|
-
};
|
|
454
|
-
toMatchTypeOf: {
|
|
455
|
-
/**
|
|
456
|
-
* A less strict version of {@linkcode toEqualTypeOf `.toEqualTypeOf()`}
|
|
457
|
-
* that allows for extra properties.
|
|
458
|
-
* This is roughly equivalent to an `extends` constraint
|
|
459
|
-
* in a function type argument.
|
|
460
|
-
*
|
|
461
|
-
* @example
|
|
462
|
-
* <caption>Using generic type argument syntax</caption>
|
|
463
|
-
* ```ts
|
|
464
|
-
* expectTypeOf({ a: 1, b: 1 }).toMatchTypeOf<{ a: number }>()
|
|
465
|
-
* ```
|
|
466
|
-
*
|
|
467
|
-
* @example
|
|
468
|
-
* <caption>Using inferred type syntax by passing a value</caption>
|
|
469
|
-
* ```ts
|
|
470
|
-
* expectTypeOf({ a: 1, b: 1 }).toMatchTypeOf({ a: 2 })
|
|
471
|
-
* ```
|
|
472
|
-
*
|
|
473
|
-
* @param value - The value to compare against the expected type.
|
|
474
|
-
* @param MISMATCH - The mismatch arguments.
|
|
475
|
-
* @returns `true`.
|
|
476
|
-
*/
|
|
477
|
-
<Expected extends Extends<Actual, Expected> extends true ? unknown : MismatchInfo<Actual, Expected>>(value: Expected & AValue, // reason for `& AValue`: make sure this is only the selected overload when the end-user passes a value for an inferred typearg. The `Mismatch` type does match `AValue`.
|
|
478
|
-
...MISMATCH: MismatchArgs<Extends<Actual, Expected>, true>): true;
|
|
479
|
-
/**
|
|
480
|
-
* A less strict version of {@linkcode toEqualTypeOf `.toEqualTypeOf()`}
|
|
481
|
-
* that allows for extra properties.
|
|
482
|
-
* This is roughly equivalent to an `extends` constraint
|
|
483
|
-
* in a function type argument.
|
|
484
|
-
*
|
|
485
|
-
* @example
|
|
486
|
-
* <caption>Using generic type argument syntax</caption>
|
|
487
|
-
* ```ts
|
|
488
|
-
* expectTypeOf({ a: 1, b: 1 }).toMatchTypeOf<{ a: number }>()
|
|
489
|
-
* ```
|
|
490
|
-
*
|
|
491
|
-
* @example
|
|
492
|
-
* <caption>Using inferred type syntax by passing a value</caption>
|
|
493
|
-
* ```ts
|
|
494
|
-
* expectTypeOf({ a: 1, b: 1 }).toMatchTypeOf({ a: 2 })
|
|
495
|
-
* ```
|
|
496
|
-
*
|
|
497
|
-
* @param MISMATCH - The mismatch arguments.
|
|
498
|
-
* @returns `true`.
|
|
499
|
-
*/
|
|
500
|
-
<Expected extends Extends<Actual, Expected> extends true ? unknown : MismatchInfo<Actual, Expected>>(...MISMATCH: MismatchArgs<Extends<Actual, Expected>, true>): true;
|
|
501
|
-
};
|
|
502
|
-
/**
|
|
503
|
-
* Checks whether an object has a given property.
|
|
504
|
-
*
|
|
505
|
-
* @example
|
|
506
|
-
* <caption>check that properties exist</caption>
|
|
507
|
-
* ```ts
|
|
508
|
-
* const obj = {a: 1, b: ''}
|
|
509
|
-
*
|
|
510
|
-
* expectTypeOf(obj).toHaveProperty('a')
|
|
511
|
-
*
|
|
512
|
-
* expectTypeOf(obj).not.toHaveProperty('c')
|
|
513
|
-
* ```
|
|
514
|
-
*
|
|
515
|
-
* @param key - The property key to check for.
|
|
516
|
-
* @param MISMATCH - The mismatch arguments.
|
|
517
|
-
* @returns `true`.
|
|
518
|
-
*/
|
|
519
|
-
toHaveProperty: <KeyType extends keyof Actual>(key: KeyType, ...MISMATCH: MismatchArgs<Extends<KeyType, keyof Actual>, true>) => KeyType extends keyof Actual ? PositiveExpectTypeOf<Actual[KeyType]> : true;
|
|
520
|
-
/**
|
|
521
|
-
* Inverts the result of the following assertions.
|
|
522
|
-
*
|
|
523
|
-
* @example
|
|
524
|
-
* ```ts
|
|
525
|
-
* expectTypeOf({ a: 1 }).not.toMatchTypeOf({ b: 1 })
|
|
526
|
-
* ```
|
|
527
|
-
*/
|
|
528
|
-
not: NegativeExpectTypeOf<Actual>;
|
|
529
|
-
/**
|
|
530
|
-
* Intersection types can cause issues with
|
|
531
|
-
* {@linkcode toEqualTypeOf `.toEqualTypeOf()`}:
|
|
532
|
-
* ```ts
|
|
533
|
-
* // ❌ The following line doesn't compile, even though the types are arguably the same.
|
|
534
|
-
* expectTypeOf<{ a: 1 } & { b: 2 }>().toEqualTypeOf<{ a: 1; b: 2 }>()
|
|
535
|
-
* ```
|
|
536
|
-
* This helper works around this problem by using
|
|
537
|
-
* a more permissive but less performant check.
|
|
538
|
-
*
|
|
539
|
-
* __Note__: This comes at a performance cost, and can cause the compiler
|
|
540
|
-
* to 'give up' if used with excessively deep types, so use sparingly.
|
|
541
|
-
*
|
|
542
|
-
* @see {@link https://github.com/mmkal/expect-type/pull/21 Reference}
|
|
543
|
-
*/
|
|
544
|
-
branded: {
|
|
545
|
-
/**
|
|
546
|
-
* Uses TypeScript's internal technique to check for type "identicalness".
|
|
547
|
-
*
|
|
548
|
-
* It will check if the types are fully equal to each other.
|
|
549
|
-
* It will not fail if two objects have different values, but the same type.
|
|
550
|
-
* It will fail however if an object is missing a property.
|
|
551
|
-
*
|
|
552
|
-
* **_Unexpected failure_**? For a more permissive but less performant
|
|
553
|
-
* check that accommodates for equivalent intersection types,
|
|
554
|
-
* use {@linkcode PositiveExpectTypeOf.branded `.branded.toEqualTypeOf()`}.
|
|
555
|
-
* @see {@link https://github.com/mmkal/expect-type#why-is-my-assertion-failing The documentation for details}.
|
|
556
|
-
*
|
|
557
|
-
* @example
|
|
558
|
-
* <caption>Using generic type argument syntax</caption>
|
|
559
|
-
* ```ts
|
|
560
|
-
* expectTypeOf({ a: 1 }).toEqualTypeOf<{ a: number }>()
|
|
561
|
-
*
|
|
562
|
-
* expectTypeOf({ a: 1, b: 1 }).not.toEqualTypeOf<{ a: number }>()
|
|
563
|
-
* ```
|
|
564
|
-
*
|
|
565
|
-
* @example
|
|
566
|
-
* <caption>Using inferred type syntax by passing a value</caption>
|
|
567
|
-
* ```ts
|
|
568
|
-
* expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 1 })
|
|
569
|
-
*
|
|
570
|
-
* expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 2 })
|
|
571
|
-
* ```
|
|
572
|
-
*
|
|
573
|
-
* @param MISMATCH - The mismatch arguments.
|
|
574
|
-
* @returns `true`.
|
|
575
|
-
*/
|
|
576
|
-
toEqualTypeOf: <Expected extends StrictEqualUsingBranding<Actual, Expected> extends true ? unknown : MismatchInfo<Actual, Expected>>(...MISMATCH: MismatchArgs<StrictEqualUsingBranding<Actual, Expected>, true>) => true;
|
|
577
|
-
};
|
|
143
|
+
interface SourceMap {
|
|
144
|
+
file: string;
|
|
145
|
+
mappings: string;
|
|
146
|
+
names: string[];
|
|
147
|
+
sources: string[];
|
|
148
|
+
sourcesContent?: string[];
|
|
149
|
+
version: number;
|
|
150
|
+
toString: () => string;
|
|
151
|
+
toUrl: () => string;
|
|
578
152
|
}
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
*
|
|
589
|
-
* It will check if the types are fully equal to each other.
|
|
590
|
-
* It will not fail if two objects have different values, but the same type.
|
|
591
|
-
* It will fail however if an object is missing a property.
|
|
592
|
-
*
|
|
593
|
-
* **_Unexpected failure_**? For a more permissive but less performant
|
|
594
|
-
* check that accommodates for equivalent intersection types,
|
|
595
|
-
* use {@linkcode PositiveExpectTypeOf.branded `.branded.toEqualTypeOf()`}.
|
|
596
|
-
* @see {@link https://github.com/mmkal/expect-type#why-is-my-assertion-failing The documentation for details}.
|
|
597
|
-
*
|
|
598
|
-
* @example
|
|
599
|
-
* <caption>Using generic type argument syntax</caption>
|
|
600
|
-
* ```ts
|
|
601
|
-
* expectTypeOf({ a: 1 }).toEqualTypeOf<{ a: number }>()
|
|
602
|
-
*
|
|
603
|
-
* expectTypeOf({ a: 1, b: 1 }).not.toEqualTypeOf<{ a: number }>()
|
|
604
|
-
* ```
|
|
605
|
-
*
|
|
606
|
-
* @example
|
|
607
|
-
* <caption>Using inferred type syntax by passing a value</caption>
|
|
608
|
-
* ```ts
|
|
609
|
-
* expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 1 })
|
|
610
|
-
*
|
|
611
|
-
* expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 2 })
|
|
612
|
-
* ```
|
|
613
|
-
*
|
|
614
|
-
* @param value - The value to compare against the expected type.
|
|
615
|
-
* @param MISMATCH - The mismatch arguments.
|
|
616
|
-
* @returns `true`.
|
|
617
|
-
*/
|
|
618
|
-
<Expected>(value: Expected & AValue, ...MISMATCH: MismatchArgs<StrictEqualUsingTSInternalIdenticalToOperator<Actual, Expected>, false>): true;
|
|
619
|
-
/**
|
|
620
|
-
* Uses TypeScript's internal technique to check for type "identicalness".
|
|
621
|
-
*
|
|
622
|
-
* It will check if the types are fully equal to each other.
|
|
623
|
-
* It will not fail if two objects have different values, but the same type.
|
|
624
|
-
* It will fail however if an object is missing a property.
|
|
625
|
-
*
|
|
626
|
-
* **_Unexpected failure_**? For a more permissive but less performant
|
|
627
|
-
* check that accommodates for equivalent intersection types,
|
|
628
|
-
* use {@linkcode PositiveExpectTypeOf.branded `.branded.toEqualTypeOf()`}.
|
|
629
|
-
* @see {@link https://github.com/mmkal/expect-type#why-is-my-assertion-failing The documentation for details}.
|
|
630
|
-
*
|
|
631
|
-
* @example
|
|
632
|
-
* <caption>Using generic type argument syntax</caption>
|
|
633
|
-
* ```ts
|
|
634
|
-
* expectTypeOf({ a: 1 }).toEqualTypeOf<{ a: number }>()
|
|
635
|
-
*
|
|
636
|
-
* expectTypeOf({ a: 1, b: 1 }).not.toEqualTypeOf<{ a: number }>()
|
|
637
|
-
* ```
|
|
638
|
-
*
|
|
639
|
-
* @example
|
|
640
|
-
* <caption>Using inferred type syntax by passing a value</caption>
|
|
641
|
-
* ```ts
|
|
642
|
-
* expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 1 })
|
|
643
|
-
*
|
|
644
|
-
* expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 2 })
|
|
645
|
-
* ```
|
|
646
|
-
*
|
|
647
|
-
* @param MISMATCH - The mismatch arguments.
|
|
648
|
-
* @returns `true`.
|
|
649
|
-
*/
|
|
650
|
-
<Expected>(...MISMATCH: MismatchArgs<StrictEqualUsingTSInternalIdenticalToOperator<Actual, Expected>, false>): true;
|
|
651
|
-
};
|
|
652
|
-
toMatchTypeOf: {
|
|
653
|
-
/**
|
|
654
|
-
* A less strict version of
|
|
655
|
-
* {@linkcode PositiveExpectTypeOf.toEqualTypeOf `.toEqualTypeOf()`}
|
|
656
|
-
* that allows for extra properties.
|
|
657
|
-
* This is roughly equivalent to an `extends` constraint
|
|
658
|
-
* in a function type argument.
|
|
659
|
-
*
|
|
660
|
-
* @example
|
|
661
|
-
* <caption>Using generic type argument syntax</caption>
|
|
662
|
-
* ```ts
|
|
663
|
-
* expectTypeOf({ a: 1, b: 1 }).toMatchTypeOf<{ a: number }>()
|
|
664
|
-
* ```
|
|
665
|
-
*
|
|
666
|
-
* @example
|
|
667
|
-
* <caption>Using inferred type syntax by passing a value</caption>
|
|
668
|
-
* ```ts
|
|
669
|
-
* expectTypeOf({ a: 1, b: 1 }).toMatchTypeOf({ a: 2 })
|
|
670
|
-
* ```
|
|
671
|
-
*
|
|
672
|
-
* @param value - The value to compare against the expected type.
|
|
673
|
-
* @param MISMATCH - The mismatch arguments.
|
|
674
|
-
* @returns `true`.
|
|
675
|
-
*/
|
|
676
|
-
<Expected>(value: Expected & AValue, // reason for `& AValue`: make sure this is only the selected overload when the end-user passes a value for an inferred typearg. The `Mismatch` type does match `AValue`.
|
|
677
|
-
...MISMATCH: MismatchArgs<Extends<Actual, Expected>, false>): true;
|
|
678
|
-
/**
|
|
679
|
-
* A less strict version of
|
|
680
|
-
* {@linkcode PositiveExpectTypeOf.toEqualTypeOf `.toEqualTypeOf()`}
|
|
681
|
-
* that allows for extra properties.
|
|
682
|
-
* This is roughly equivalent to an `extends` constraint
|
|
683
|
-
* in a function type argument.
|
|
684
|
-
*
|
|
685
|
-
* @example
|
|
686
|
-
* <caption>Using generic type argument syntax</caption>
|
|
687
|
-
* ```ts
|
|
688
|
-
* expectTypeOf({ a: 1, b: 1 }).toMatchTypeOf<{ a: number }>()
|
|
689
|
-
* ```
|
|
690
|
-
*
|
|
691
|
-
* @example
|
|
692
|
-
* <caption>Using inferred type syntax by passing a value</caption>
|
|
693
|
-
* ```ts
|
|
694
|
-
* expectTypeOf({ a: 1, b: 1 }).toMatchTypeOf({ a: 2 })
|
|
695
|
-
* ```
|
|
696
|
-
*
|
|
697
|
-
* @param MISMATCH - The mismatch arguments.
|
|
698
|
-
* @returns `true`.
|
|
699
|
-
*/
|
|
700
|
-
<Expected>(...MISMATCH: MismatchArgs<Extends<Actual, Expected>, false>): true;
|
|
701
|
-
};
|
|
702
|
-
/**
|
|
703
|
-
* Checks whether an object has a given property.
|
|
704
|
-
*
|
|
705
|
-
* @example
|
|
706
|
-
* <caption>check that properties exist</caption>
|
|
707
|
-
* ```ts
|
|
708
|
-
* const obj = {a: 1, b: ''}
|
|
709
|
-
*
|
|
710
|
-
* expectTypeOf(obj).toHaveProperty('a')
|
|
711
|
-
*
|
|
712
|
-
* expectTypeOf(obj).not.toHaveProperty('c')
|
|
713
|
-
* ```
|
|
714
|
-
*
|
|
715
|
-
* @param key - The property key to check for.
|
|
716
|
-
* @param MISMATCH - The mismatch arguments.
|
|
717
|
-
* @returns `true`.
|
|
718
|
-
*/
|
|
719
|
-
toHaveProperty: <KeyType extends string | number | symbol>(key: KeyType, ...MISMATCH: MismatchArgs<Extends<KeyType, keyof Actual>, false>) => true;
|
|
153
|
+
interface TransformResultWithSource {
|
|
154
|
+
code: string;
|
|
155
|
+
map: SourceMap | {
|
|
156
|
+
mappings: '';
|
|
157
|
+
} | null;
|
|
158
|
+
etag?: string;
|
|
159
|
+
deps?: string[];
|
|
160
|
+
dynamicDeps?: string[];
|
|
161
|
+
source?: string;
|
|
720
162
|
}
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
interface BaseExpectTypeOf<Actual, Options extends {
|
|
735
|
-
positive: boolean;
|
|
736
|
-
}> {
|
|
737
|
-
/**
|
|
738
|
-
* Checks whether the type of the value is `any`.
|
|
739
|
-
*/
|
|
740
|
-
toBeAny: Scolder<ExpectAny<Actual>, Options>;
|
|
741
|
-
/**
|
|
742
|
-
* Checks whether the type of the value is `unknown`.
|
|
743
|
-
*/
|
|
744
|
-
toBeUnknown: Scolder<ExpectUnknown<Actual>, Options>;
|
|
745
|
-
/**
|
|
746
|
-
* Checks whether the type of the value is `never`.
|
|
747
|
-
*/
|
|
748
|
-
toBeNever: Scolder<ExpectNever<Actual>, Options>;
|
|
749
|
-
/**
|
|
750
|
-
* Checks whether the type of the value is `function`.
|
|
751
|
-
*/
|
|
752
|
-
toBeFunction: Scolder<ExpectFunction<Actual>, Options>;
|
|
753
|
-
/**
|
|
754
|
-
* Checks whether the type of the value is `object`.
|
|
755
|
-
*/
|
|
756
|
-
toBeObject: Scolder<ExpectObject<Actual>, Options>;
|
|
757
|
-
/**
|
|
758
|
-
* Checks whether the type of the value is an {@linkcode Array}.
|
|
759
|
-
*/
|
|
760
|
-
toBeArray: Scolder<ExpectArray<Actual>, Options>;
|
|
761
|
-
/**
|
|
762
|
-
* Checks whether the type of the value is `number`.
|
|
763
|
-
*/
|
|
764
|
-
toBeNumber: Scolder<ExpectNumber<Actual>, Options>;
|
|
765
|
-
/**
|
|
766
|
-
* Checks whether the type of the value is `string`.
|
|
767
|
-
*/
|
|
768
|
-
toBeString: Scolder<ExpectString<Actual>, Options>;
|
|
769
|
-
/**
|
|
770
|
-
* Checks whether the type of the value is `boolean`.
|
|
771
|
-
*/
|
|
772
|
-
toBeBoolean: Scolder<ExpectBoolean<Actual>, Options>;
|
|
773
|
-
/**
|
|
774
|
-
* Checks whether the type of the value is `void`.
|
|
775
|
-
*/
|
|
776
|
-
toBeVoid: Scolder<ExpectVoid<Actual>, Options>;
|
|
777
|
-
/**
|
|
778
|
-
* Checks whether the type of the value is `symbol`.
|
|
779
|
-
*/
|
|
780
|
-
toBeSymbol: Scolder<ExpectSymbol<Actual>, Options>;
|
|
781
|
-
/**
|
|
782
|
-
* Checks whether the type of the value is `null`.
|
|
783
|
-
*/
|
|
784
|
-
toBeNull: Scolder<ExpectNull<Actual>, Options>;
|
|
785
|
-
/**
|
|
786
|
-
* Checks whether the type of the value is `undefined`.
|
|
787
|
-
*/
|
|
788
|
-
toBeUndefined: Scolder<ExpectUndefined<Actual>, Options>;
|
|
789
|
-
/**
|
|
790
|
-
* Checks whether the type of the value is `null` or `undefined`.
|
|
791
|
-
*/
|
|
792
|
-
toBeNullable: Scolder<ExpectNullable<Actual>, Options>;
|
|
793
|
-
/**
|
|
794
|
-
* Checks whether a function is callable with the given parameters.
|
|
795
|
-
*
|
|
796
|
-
* __Note__: You cannot negate this assertion with
|
|
797
|
-
* {@linkcode PositiveExpectTypeOf.not `.not`} you need to use
|
|
798
|
-
* `ts-expect-error` instead.
|
|
799
|
-
*
|
|
800
|
-
* @example
|
|
801
|
-
* ```ts
|
|
802
|
-
* const f = (a: number) => [a, a]
|
|
803
|
-
*
|
|
804
|
-
* expectTypeOf(f).toBeCallableWith(1)
|
|
805
|
-
* ```
|
|
806
|
-
*
|
|
807
|
-
* __Known Limitation__: This assertion will likely fail if you try to use it
|
|
808
|
-
* with a generic function or an overload.
|
|
809
|
-
* @see {@link https://github.com/mmkal/expect-type/issues/50 This issue} for an example and a workaround.
|
|
810
|
-
*
|
|
811
|
-
* @param args - The arguments to check for callability.
|
|
812
|
-
* @returns `true`.
|
|
813
|
-
*/
|
|
814
|
-
toBeCallableWith: Options['positive'] extends true ? (...args: Params<Actual>) => true : never;
|
|
815
|
-
/**
|
|
816
|
-
* Checks whether a class is constructible with the given parameters.
|
|
817
|
-
*
|
|
818
|
-
* @example
|
|
819
|
-
* ```ts
|
|
820
|
-
* expectTypeOf(Date).toBeConstructibleWith('1970')
|
|
821
|
-
*
|
|
822
|
-
* expectTypeOf(Date).toBeConstructibleWith(0)
|
|
823
|
-
*
|
|
824
|
-
* expectTypeOf(Date).toBeConstructibleWith(new Date())
|
|
825
|
-
*
|
|
826
|
-
* expectTypeOf(Date).toBeConstructibleWith()
|
|
827
|
-
* ```
|
|
828
|
-
*
|
|
829
|
-
* @param args - The arguments to check for constructibility.
|
|
830
|
-
* @returns `true`.
|
|
831
|
-
*/
|
|
832
|
-
toBeConstructibleWith: Options['positive'] extends true ? (...args: ConstructorParams<Actual>) => true : never;
|
|
833
|
-
/**
|
|
834
|
-
* Equivalent to the {@linkcode Extract} utility type.
|
|
835
|
-
* Helps narrow down complex union types.
|
|
836
|
-
*
|
|
837
|
-
* @example
|
|
838
|
-
* ```ts
|
|
839
|
-
* type ResponsiveProp<T> = T | T[] | { xs?: T; sm?: T; md?: T }
|
|
840
|
-
*
|
|
841
|
-
* interface CSSProperties {
|
|
842
|
-
* margin?: string
|
|
843
|
-
* padding?: string
|
|
844
|
-
* }
|
|
845
|
-
*
|
|
846
|
-
* function getResponsiveProp<T>(_props: T): ResponsiveProp<T> {
|
|
847
|
-
* return {}
|
|
848
|
-
* }
|
|
849
|
-
*
|
|
850
|
-
* const cssProperties: CSSProperties = { margin: '1px', padding: '2px' }
|
|
851
|
-
*
|
|
852
|
-
* expectTypeOf(getResponsiveProp(cssProperties))
|
|
853
|
-
* .extract<{ xs?: any }>() // extracts the last type from a union
|
|
854
|
-
* .toEqualTypeOf<{
|
|
855
|
-
* xs?: CSSProperties
|
|
856
|
-
* sm?: CSSProperties
|
|
857
|
-
* md?: CSSProperties
|
|
858
|
-
* }>()
|
|
859
|
-
*
|
|
860
|
-
* expectTypeOf(getResponsiveProp(cssProperties))
|
|
861
|
-
* .extract<unknown[]>() // extracts an array from a union
|
|
862
|
-
* .toEqualTypeOf<CSSProperties[]>()
|
|
863
|
-
* ```
|
|
864
|
-
*
|
|
865
|
-
* __Note__: If no type is found in the union, it will return `never`.
|
|
866
|
-
*
|
|
867
|
-
* @param v - The type to extract from the union.
|
|
868
|
-
* @returns The type after extracting the type from the union.
|
|
869
|
-
*/
|
|
870
|
-
extract: <V>(v?: V) => ExpectTypeOf<Extract<Actual, V>, Options>;
|
|
871
|
-
/**
|
|
872
|
-
* Equivalent to the {@linkcode Exclude} utility type.
|
|
873
|
-
* Removes types from a union.
|
|
874
|
-
*
|
|
875
|
-
* @example
|
|
876
|
-
* ```ts
|
|
877
|
-
* type ResponsiveProp<T> = T | T[] | { xs?: T; sm?: T; md?: T }
|
|
878
|
-
*
|
|
879
|
-
* interface CSSProperties {
|
|
880
|
-
* margin?: string
|
|
881
|
-
* padding?: string
|
|
882
|
-
* }
|
|
883
|
-
*
|
|
884
|
-
* function getResponsiveProp<T>(_props: T): ResponsiveProp<T> {
|
|
885
|
-
* return {}
|
|
886
|
-
* }
|
|
887
|
-
*
|
|
888
|
-
* const cssProperties: CSSProperties = { margin: '1px', padding: '2px' }
|
|
889
|
-
*
|
|
890
|
-
* expectTypeOf(getResponsiveProp(cssProperties))
|
|
891
|
-
* .exclude<unknown[]>()
|
|
892
|
-
* .exclude<{ xs?: unknown }>() // or just `.exclude<unknown[] | { xs?: unknown }>()`
|
|
893
|
-
* .toEqualTypeOf<CSSProperties>()
|
|
894
|
-
* ```
|
|
895
|
-
*/
|
|
896
|
-
exclude: <V>(v?: V) => ExpectTypeOf<Exclude<Actual, V>, Options>;
|
|
897
|
-
/**
|
|
898
|
-
* Equivalent to the {@linkcode Pick} utility type.
|
|
899
|
-
* Helps select a subset of properties from an object type.
|
|
900
|
-
*
|
|
901
|
-
* @example
|
|
902
|
-
* ```ts
|
|
903
|
-
* interface Person {
|
|
904
|
-
* name: string
|
|
905
|
-
* age: number
|
|
906
|
-
* }
|
|
907
|
-
*
|
|
908
|
-
* expectTypeOf<Person>()
|
|
909
|
-
* .pick<'name'>()
|
|
910
|
-
* .toEqualTypeOf<{ name: string }>()
|
|
911
|
-
* ```
|
|
912
|
-
*
|
|
913
|
-
* @param keyToPick - The property key to pick.
|
|
914
|
-
* @returns The type after picking the property.
|
|
915
|
-
*/
|
|
916
|
-
pick: <KeyToPick extends keyof Actual>(keyToPick?: KeyToPick) => ExpectTypeOf<Pick<Actual, KeyToPick>, Options>;
|
|
917
|
-
/**
|
|
918
|
-
* Equivalent to the {@linkcode Omit} utility type.
|
|
919
|
-
* Helps remove a subset of properties from an object type.
|
|
920
|
-
*
|
|
921
|
-
* @example
|
|
922
|
-
* ```ts
|
|
923
|
-
* interface Person {
|
|
924
|
-
* name: string
|
|
925
|
-
* age: number
|
|
926
|
-
* }
|
|
927
|
-
*
|
|
928
|
-
* expectTypeOf<Person>().omit<'name'>().toEqualTypeOf<{ age: number }>()
|
|
929
|
-
* ```
|
|
930
|
-
*
|
|
931
|
-
* @param keyToOmit - The property key to omit.
|
|
932
|
-
* @returns The type after omitting the property.
|
|
933
|
-
*/
|
|
934
|
-
omit: <KeyToOmit extends keyof Actual | (PropertyKey & Record<never, never>)>(keyToOmit?: KeyToOmit) => ExpectTypeOf<Omit<Actual, KeyToOmit>, Options>;
|
|
935
|
-
/**
|
|
936
|
-
* Extracts a certain function argument with `.parameter(number)` call to
|
|
937
|
-
* perform other assertions on it.
|
|
938
|
-
*
|
|
939
|
-
* @example
|
|
940
|
-
* ```ts
|
|
941
|
-
* function foo(a: number, b: string) {
|
|
942
|
-
* return [a, b]
|
|
943
|
-
* }
|
|
944
|
-
*
|
|
945
|
-
* expectTypeOf(foo).parameter(0).toBeNumber()
|
|
946
|
-
*
|
|
947
|
-
* expectTypeOf(foo).parameter(1).toBeString()
|
|
948
|
-
* ```
|
|
949
|
-
*
|
|
950
|
-
* @param index - The index of the parameter to extract.
|
|
951
|
-
* @returns The extracted parameter type.
|
|
952
|
-
*/
|
|
953
|
-
parameter: <Index extends keyof Params<Actual>>(index: Index) => ExpectTypeOf<Params<Actual>[Index], Options>;
|
|
954
|
-
/**
|
|
955
|
-
* Equivalent to the {@linkcode Parameters} utility type.
|
|
956
|
-
* Extracts function parameters to perform assertions on its value.
|
|
957
|
-
* Parameters are returned as an array.
|
|
958
|
-
*
|
|
959
|
-
* @example
|
|
960
|
-
* ```ts
|
|
961
|
-
* function noParam() {}
|
|
962
|
-
*
|
|
963
|
-
* function hasParam(s: string) {}
|
|
964
|
-
*
|
|
965
|
-
* expectTypeOf(noParam).parameters.toEqualTypeOf<[]>()
|
|
966
|
-
*
|
|
967
|
-
* expectTypeOf(hasParam).parameters.toEqualTypeOf<[string]>()
|
|
968
|
-
* ```
|
|
969
|
-
*/
|
|
970
|
-
parameters: ExpectTypeOf<Params<Actual>, Options>;
|
|
971
|
-
/**
|
|
972
|
-
* Equivalent to the {@linkcode ConstructorParameters} utility type.
|
|
973
|
-
* Extracts constructor parameters as an array of values and
|
|
974
|
-
* perform assertions on them with this method.
|
|
975
|
-
*
|
|
976
|
-
* @example
|
|
977
|
-
* ```ts
|
|
978
|
-
* expectTypeOf(Date).constructorParameters.toEqualTypeOf<
|
|
979
|
-
* [] | [string | number | Date]
|
|
980
|
-
* >()
|
|
981
|
-
* ```
|
|
982
|
-
*/
|
|
983
|
-
constructorParameters: ExpectTypeOf<ConstructorParams<Actual>, Options>;
|
|
984
|
-
/**
|
|
985
|
-
* Equivalent to the {@linkcode ThisParameterType} utility type.
|
|
986
|
-
* Extracts the `this` parameter of a function to
|
|
987
|
-
* perform assertions on its value.
|
|
988
|
-
*
|
|
989
|
-
* @example
|
|
990
|
-
* ```ts
|
|
991
|
-
* function greet(this: { name: string }, message: string) {
|
|
992
|
-
* return `Hello ${this.name}, here's your message: ${message}`
|
|
993
|
-
* }
|
|
994
|
-
*
|
|
995
|
-
* expectTypeOf(greet).thisParameter.toEqualTypeOf<{ name: string }>()
|
|
996
|
-
* ```
|
|
997
|
-
*/
|
|
998
|
-
thisParameter: ExpectTypeOf<ThisParameterType<Actual>, Options>;
|
|
999
|
-
/**
|
|
1000
|
-
* Equivalent to the {@linkcode InstanceType} utility type.
|
|
1001
|
-
* Extracts the instance type of a class to perform assertions on.
|
|
1002
|
-
*
|
|
1003
|
-
* @example
|
|
1004
|
-
* ```ts
|
|
1005
|
-
* expectTypeOf(Date).instance.toHaveProperty('toISOString')
|
|
1006
|
-
* ```
|
|
1007
|
-
*/
|
|
1008
|
-
instance: Actual extends new (...args: any[]) => infer I ? ExpectTypeOf<I, Options> : never;
|
|
1009
|
-
/**
|
|
1010
|
-
* Equivalent to the {@linkcode ReturnType} utility type.
|
|
1011
|
-
* Extracts the return type of a function.
|
|
1012
|
-
*
|
|
1013
|
-
* @example
|
|
1014
|
-
* ```ts
|
|
1015
|
-
* expectTypeOf(() => {}).returns.toBeVoid()
|
|
1016
|
-
*
|
|
1017
|
-
* expectTypeOf((a: number) => [a, a]).returns.toEqualTypeOf([1, 2])
|
|
1018
|
-
* ```
|
|
1019
|
-
*/
|
|
1020
|
-
returns: Actual extends (...args: any[]) => infer R ? ExpectTypeOf<R, Options> : never;
|
|
1021
|
-
/**
|
|
1022
|
-
* Extracts resolved value of a Promise,
|
|
1023
|
-
* so you can perform other assertions on it.
|
|
1024
|
-
*
|
|
1025
|
-
* @example
|
|
1026
|
-
* ```ts
|
|
1027
|
-
* async function asyncFunc() {
|
|
1028
|
-
* return 123
|
|
1029
|
-
* }
|
|
1030
|
-
*
|
|
1031
|
-
* expectTypeOf(asyncFunc).returns.resolves.toBeNumber()
|
|
1032
|
-
*
|
|
1033
|
-
* expectTypeOf(Promise.resolve('string')).resolves.toBeString()
|
|
1034
|
-
* ```
|
|
1035
|
-
*
|
|
1036
|
-
* Type Equivalent:
|
|
1037
|
-
* ```ts
|
|
1038
|
-
* type Resolves<PromiseType> = PromiseType extends PromiseLike<infer ResolvedType>
|
|
1039
|
-
* ? ResolvedType
|
|
1040
|
-
* : never
|
|
1041
|
-
* ```
|
|
1042
|
-
*/
|
|
1043
|
-
resolves: Actual extends PromiseLike<infer ResolvedType> ? ExpectTypeOf<ResolvedType, Options> : never;
|
|
1044
|
-
/**
|
|
1045
|
-
* Extracts array item type to perform assertions on.
|
|
1046
|
-
*
|
|
1047
|
-
* @example
|
|
1048
|
-
* ```ts
|
|
1049
|
-
* expectTypeOf([1, 2, 3]).items.toEqualTypeOf<number>()
|
|
1050
|
-
*
|
|
1051
|
-
* expectTypeOf([1, 2, 3]).items.not.toEqualTypeOf<string>()
|
|
1052
|
-
* ```
|
|
1053
|
-
*
|
|
1054
|
-
* __Type Equivalent__:
|
|
1055
|
-
* ```ts
|
|
1056
|
-
* type Items<ArrayType> = ArrayType extends ArrayLike<infer ItemType>
|
|
1057
|
-
* ? ItemType
|
|
1058
|
-
* : never
|
|
1059
|
-
* ```
|
|
1060
|
-
*/
|
|
1061
|
-
items: Actual extends ArrayLike<infer ItemType> ? ExpectTypeOf<ItemType, Options> : never;
|
|
1062
|
-
/**
|
|
1063
|
-
* Extracts the type guarded by a function to perform assertions on.
|
|
1064
|
-
*
|
|
1065
|
-
* @example
|
|
1066
|
-
* ```ts
|
|
1067
|
-
* function isString(v: any): v is string {
|
|
1068
|
-
* return typeof v === 'string'
|
|
1069
|
-
* }
|
|
1070
|
-
*
|
|
1071
|
-
* expectTypeOf(isString).guards.toBeString()
|
|
1072
|
-
* ```
|
|
1073
|
-
*/
|
|
1074
|
-
guards: Actual extends (v: any, ...args: any[]) => v is infer T ? ExpectTypeOf<T, Options> : never;
|
|
1075
|
-
/**
|
|
1076
|
-
* Extracts the type asserted by a function to perform assertions on.
|
|
1077
|
-
*
|
|
1078
|
-
* @example
|
|
1079
|
-
* ```ts
|
|
1080
|
-
* function assertNumber(v: any): asserts v is number {
|
|
1081
|
-
* if (typeof v !== 'number')
|
|
1082
|
-
* throw new TypeError('Nope !')
|
|
1083
|
-
* }
|
|
1084
|
-
*
|
|
1085
|
-
* expectTypeOf(assertNumber).asserts.toBeNumber()
|
|
1086
|
-
* ```
|
|
1087
|
-
*/
|
|
1088
|
-
asserts: Actual extends (v: any, ...args: any[]) => asserts v is infer T ? unknown extends T ? never : ExpectTypeOf<T, Options> : never;
|
|
163
|
+
interface WebSocketHandlers {
|
|
164
|
+
onTaskUpdate: (packs: TaskResultPack$1[]) => void;
|
|
165
|
+
getFiles: () => File$1[];
|
|
166
|
+
getTestFiles: () => Promise<SerializedTestSpecification[]>;
|
|
167
|
+
getPaths: () => string[];
|
|
168
|
+
getConfig: () => SerializedConfig;
|
|
169
|
+
getModuleGraph: (projectName: string, id: string, browser?: boolean) => Promise<ModuleGraphData>;
|
|
170
|
+
getTransformResult: (projectName: string, id: string, browser?: boolean) => Promise<TransformResultWithSource | undefined>;
|
|
171
|
+
readTestFile: (id: string) => Promise<string | null>;
|
|
172
|
+
saveTestFile: (id: string, content: string) => Promise<void>;
|
|
173
|
+
rerun: (files: string[]) => Promise<void>;
|
|
174
|
+
updateSnapshot: (file?: File$1) => Promise<void>;
|
|
175
|
+
getUnhandledErrors: () => unknown[];
|
|
1089
176
|
}
|
|
177
|
+
interface WebSocketEvents {
|
|
178
|
+
onCollected?: (files?: File$1[]) => Awaitable$1<void>;
|
|
179
|
+
onFinished?: (files: File$1[], errors: unknown[], coverage?: unknown) => Awaitable$1<void>;
|
|
180
|
+
onTaskUpdate?: (packs: TaskResultPack$1[]) => Awaitable$1<void>;
|
|
181
|
+
onUserConsoleLog?: (log: UserConsoleLog) => Awaitable$1<void>;
|
|
182
|
+
onPathsCollected?: (paths?: string[]) => Awaitable$1<void>;
|
|
183
|
+
onSpecsCollected?: (specs?: SerializedTestSpecification[]) => Awaitable$1<void>;
|
|
184
|
+
onFinishedReportCoverage: () => void;
|
|
185
|
+
}
|
|
186
|
+
type WebSocketRPC = BirpcReturn<WebSocketEvents, WebSocketHandlers>;
|
|
187
|
+
|
|
188
|
+
declare function createExpect(test?: TaskPopulated): ExpectStatic;
|
|
189
|
+
declare const globalExpect: ExpectStatic;
|
|
190
|
+
|
|
1090
191
|
/**
|
|
1091
|
-
*
|
|
1092
|
-
|
|
1093
|
-
declare type _ExpectTypeOf = {
|
|
1094
|
-
/**
|
|
1095
|
-
* Asserts the expected type of a value.
|
|
1096
|
-
*
|
|
1097
|
-
* @param actual - The actual value being asserted.
|
|
1098
|
-
* @returns An object representing the expected type assertion.
|
|
1099
|
-
*/
|
|
1100
|
-
<Actual>(actual: Actual): ExpectTypeOf<Actual, {
|
|
1101
|
-
positive: true;
|
|
1102
|
-
branded: false;
|
|
1103
|
-
}>;
|
|
1104
|
-
/**
|
|
1105
|
-
* Asserts the expected type of a value without providing an actual value.
|
|
1106
|
-
*
|
|
1107
|
-
* @returns An object representing the expected type assertion.
|
|
1108
|
-
*/
|
|
1109
|
-
<Actual>(): ExpectTypeOf<Actual, {
|
|
1110
|
-
positive: true;
|
|
1111
|
-
branded: false;
|
|
1112
|
-
}>;
|
|
1113
|
-
};
|
|
1114
|
-
/**
|
|
1115
|
-
* Similar to Jest's `expect`, but with type-awareness.
|
|
1116
|
-
* Gives you access to a number of type-matchers that let you make assertions about the
|
|
1117
|
-
* form of a reference or generic type parameter.
|
|
1118
|
-
*
|
|
1119
|
-
* @example
|
|
1120
|
-
* import {foo, bar} from '../foo'
|
|
1121
|
-
* import {expectTypeOf} from 'expect-type'
|
|
1122
|
-
*
|
|
1123
|
-
* test('foo types', () => {
|
|
1124
|
-
* // make sure `foo` has type {a: number}
|
|
1125
|
-
* expectTypeOf(foo).toMatchTypeOf({a: 1})
|
|
1126
|
-
* expectTypeOf(foo).toHaveProperty('a').toBeNumber()
|
|
1127
|
-
*
|
|
1128
|
-
* // make sure `bar` is a function taking a string:
|
|
1129
|
-
* expectTypeOf(bar).parameter(0).toBeString()
|
|
1130
|
-
* expectTypeOf(bar).returns.not.toBeAny()
|
|
1131
|
-
* })
|
|
1132
|
-
*
|
|
1133
|
-
* @description
|
|
1134
|
-
* See the [full docs](https://npmjs.com/package/expect-type#documentation) for lots more examples.
|
|
192
|
+
* Gives access to injected context provided from the main thread.
|
|
193
|
+
* This usually returns a value provided by `globalSetup` or an external library.
|
|
1135
194
|
*/
|
|
1136
|
-
declare
|
|
1137
|
-
|
|
1138
|
-
interface AssertType {
|
|
1139
|
-
<T>(value: T): void;
|
|
1140
|
-
}
|
|
1141
|
-
declare const assertType: AssertType;
|
|
195
|
+
declare function inject<T extends keyof ProvidedContext & string>(key: T): ProvidedContext[T];
|
|
1142
196
|
|
|
1143
197
|
/**
|
|
1144
198
|
* This utils allows computational intensive tasks to only be ran once
|
|
@@ -1159,8 +213,8 @@ declare function runOnce<T>(fn: () => T, key?: string): T;
|
|
|
1159
213
|
*/
|
|
1160
214
|
declare function isFirstRun(): boolean;
|
|
1161
215
|
|
|
1162
|
-
declare function
|
|
1163
|
-
declare
|
|
216
|
+
declare function getRunningMode(): "watch" | "run";
|
|
217
|
+
declare function isWatchMode(): boolean;
|
|
1164
218
|
|
|
1165
219
|
type WaitForCallback<T> = () => T | Promise<T>;
|
|
1166
220
|
interface WaitForOptions {
|
|
@@ -1508,65 +562,16 @@ interface VitestUtils {
|
|
|
1508
562
|
declare const vitest: VitestUtils;
|
|
1509
563
|
declare const vi: VitestUtils;
|
|
1510
564
|
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
* Gives access to injected context provided from the main thread.
|
|
1516
|
-
* This usually returns a value provided by `globalSetup` or an external library.
|
|
1517
|
-
*/
|
|
1518
|
-
declare function inject<T extends keyof ProvidedContext & string>(key: T): ProvidedContext[T];
|
|
565
|
+
interface AssertType {
|
|
566
|
+
<T>(value: T): void;
|
|
567
|
+
}
|
|
568
|
+
declare const assertType: AssertType;
|
|
1519
569
|
|
|
1520
570
|
interface BrowserUI {
|
|
1521
571
|
setCurrentFileId: (fileId: string) => void;
|
|
1522
572
|
setIframeViewport: (width: number, height: number) => Promise<void>;
|
|
1523
573
|
}
|
|
1524
574
|
|
|
1525
|
-
interface SourceMap {
|
|
1526
|
-
file: string;
|
|
1527
|
-
mappings: string;
|
|
1528
|
-
names: string[];
|
|
1529
|
-
sources: string[];
|
|
1530
|
-
sourcesContent?: string[];
|
|
1531
|
-
version: number;
|
|
1532
|
-
toString: () => string;
|
|
1533
|
-
toUrl: () => string;
|
|
1534
|
-
}
|
|
1535
|
-
interface TransformResultWithSource {
|
|
1536
|
-
code: string;
|
|
1537
|
-
map: SourceMap | {
|
|
1538
|
-
mappings: '';
|
|
1539
|
-
} | null;
|
|
1540
|
-
etag?: string;
|
|
1541
|
-
deps?: string[];
|
|
1542
|
-
dynamicDeps?: string[];
|
|
1543
|
-
source?: string;
|
|
1544
|
-
}
|
|
1545
|
-
interface WebSocketHandlers {
|
|
1546
|
-
onTaskUpdate: (packs: TaskResultPack$1[]) => void;
|
|
1547
|
-
getFiles: () => File$1[];
|
|
1548
|
-
getTestFiles: () => Promise<SerializedTestSpecification[]>;
|
|
1549
|
-
getPaths: () => string[];
|
|
1550
|
-
getConfig: () => SerializedConfig;
|
|
1551
|
-
getModuleGraph: (projectName: string, id: string, browser?: boolean) => Promise<ModuleGraphData>;
|
|
1552
|
-
getTransformResult: (projectName: string, id: string, browser?: boolean) => Promise<TransformResultWithSource | undefined>;
|
|
1553
|
-
readTestFile: (id: string) => Promise<string | null>;
|
|
1554
|
-
saveTestFile: (id: string, content: string) => Promise<void>;
|
|
1555
|
-
rerun: (files: string[]) => Promise<void>;
|
|
1556
|
-
updateSnapshot: (file?: File$1) => Promise<void>;
|
|
1557
|
-
getUnhandledErrors: () => unknown[];
|
|
1558
|
-
}
|
|
1559
|
-
interface WebSocketEvents {
|
|
1560
|
-
onCollected?: (files?: File$1[]) => Awaitable$1<void>;
|
|
1561
|
-
onFinished?: (files: File$1[], errors: unknown[], coverage?: unknown) => Awaitable$1<void>;
|
|
1562
|
-
onTaskUpdate?: (packs: TaskResultPack$1[]) => Awaitable$1<void>;
|
|
1563
|
-
onUserConsoleLog?: (log: UserConsoleLog) => Awaitable$1<void>;
|
|
1564
|
-
onPathsCollected?: (paths?: string[]) => Awaitable$1<void>;
|
|
1565
|
-
onSpecsCollected?: (specs?: SerializedTestSpecification[]) => Awaitable$1<void>;
|
|
1566
|
-
onFinishedReportCoverage: () => void;
|
|
1567
|
-
}
|
|
1568
|
-
type WebSocketRPC = BirpcReturn<WebSocketEvents, WebSocketHandlers>;
|
|
1569
|
-
|
|
1570
575
|
/** @deprecated import `TypeCheckRawErrorsMap` from `vitest/node` instead */
|
|
1571
576
|
type RawErrsMap = RawErrsMap$1;
|
|
1572
577
|
/** @deprecated import `TypeCheckErrorInfo` from `vitest/node` instead */
|
|
@@ -1707,4 +712,4 @@ type SerializableSpec = SerializedTestSpecification;
|
|
|
1707
712
|
/** @deprecated import from `vitest/node` instead */
|
|
1708
713
|
type BenchmarkUserOptions = BenchmarkUserOptions$1;
|
|
1709
714
|
|
|
1710
|
-
export { type ApiConfig, type ArgumentsType, type Arrayable, type AssertType, type Awaitable, type BaseCoverageOptions, BenchmarkResult, type BenchmarkUserOptions, type BrowserConfigOptions, type BrowserScript, type BrowserUI, type BuiltinEnvironment, type CSSModuleScopeStrategy, type CollectLineNumbers, type CollectLines, type Constructable, type Context, type CoverageIstanbulOptions, type CoverageOptions, type CoverageProvider, type CoverageProviderModule, type CoverageReporter, type CoverageV8Options, type Custom, type CustomProviderOptions, type DepsOptimizationOptions, type DoneCallback, type Environment, type EnvironmentOptions, type EnvironmentReturn, type
|
|
715
|
+
export { type ApiConfig, type ArgumentsType, type Arrayable, type AssertType, type Awaitable, type BaseCoverageOptions, BenchmarkResult, type BenchmarkUserOptions, type BrowserConfigOptions, type BrowserScript, type BrowserUI, type BuiltinEnvironment, type CSSModuleScopeStrategy, type CollectLineNumbers, type CollectLines, type Constructable, type Context, type CoverageIstanbulOptions, type CoverageOptions, type CoverageProvider, type CoverageProviderModule, type CoverageReporter, type CoverageV8Options, type Custom, type CustomProviderOptions, type DepsOptimizationOptions, type DoneCallback, type Environment, type EnvironmentOptions, type EnvironmentReturn, type File, type HappyDOMOptions, type InlineConfig, type JSDOMOptions, ModuleGraphData, type MutableArray, type Nullable, type OnServerRestartHandler, type Pool, type PoolOptions, type ProjectConfig, ProvidedContext, type RawErrsMap, type ReportContext, type Reporter, type ResolvedConfig, type ResolvedCoverageOptions, type ResolvedTestEnvironment, type RootAndTarget, type RuntimeContext, type SequenceHooks, type SequenceSetupFiles, type SerializableSpec, SerializedConfig, SerializedTestSpecification, type Suite, type SuiteHooks, type Task, type TaskBase, type TaskResult, type TaskResultPack, type Test, type TransformModePatterns, type TransformResultWithSource, type TscErrorInfo, type TypecheckConfig, type UserConfig, UserConsoleLog, type UserWorkspaceConfig, type Vitest, type VitestEnvironment, type VitestRunMode, type VitestUtils, type VmEnvironmentReturn, type WebSocketEvents, type WebSocketHandlers, type WebSocketRPC, type WorkerContext, type WorkerRPC, assertType, createExpect, globalExpect as expect, getRunningMode, inject, isFirstRun, isWatchMode, runOnce, vi, vitest };
|