Skip to content
Myr

env.test-d.ts

This file

Path

test-d/arguments/env.test-d.ts

31 lines · 1.5 KiB · TypeScript

Last changed by

Move type tests from `tsd` to `nz`Sindre Sorhusbefore adoption2141147

History of this file

Take it

define env type (#1141)Kevin Ingersollbefore adoption607a0ff

line 1why, one step back
1import process, {type env} from 'node:process';

Move type tests from `tsd` to `nz`Sindre Sorhusbefore adoption2141147

line 2why, one step back
2import {expectTypeOf} from 'nz';

define env type (#1141)Kevin Ingersollbefore adoption607a0ff

lines 3–20why, one step back
3import {execa, type Options, type Result} from '../../index.js';
45type NodeEnv = 'production' | 'development' | 'test';67// Libraries like Next.js or Remix do the following type augmentation.8// The following type tests ensure this works with Execa.9// See https://github.com/sindresorhus/execa/pull/1141 and https://github.com/sindresorhus/execa/issues/113210declare global {11 // eslint-disable-next-line @typescript-eslint/no-namespace12 namespace NodeJS {13 // eslint-disable-next-line @typescript-eslint/consistent-type-definitions14 interface ProcessEnv {15 readonly NODE_ENV: NodeEnv;16 }17 }18}1920// The global types are impacted

Move type tests from `tsd` to `nz`Sindre Sorhusbefore adoption2141147

lines 21–24why, one step back
21expectTypeOf(process.env.NODE_ENV).toBe<NodeEnv>();
22expectTypeOf('' as (typeof env)['NODE_ENV']).toBe<NodeEnv>();23expectTypeOf('' as NodeJS.ProcessEnv['NODE_ENV']).toBe<NodeEnv>();24expectTypeOf('' as globalThis.NodeJS.ProcessEnv['NODE_ENV']).toBe<NodeEnv>();

define env type (#1141)Kevin Ingersollbefore adoption607a0ff

lines 25–26why, one step back
25
26// But Execa's types are not impacted

Move type tests from `tsd` to `nz`Sindre Sorhusbefore adoption2141147

lines 27–31why, one step back
27expectTypeOf('' as Exclude<Options['env'], undefined>['NODE_ENV']).toBe<string | undefined>();
28expectTypeOf(await execa({env: {test: 'example'}})`unicorns`).toBeAssignableTo<Result>();29expectTypeOf(await execa({env: {test: 'example'} as const})`unicorns`).toBeAssignableTo<Result>();30expectTypeOf(await execa({env: {test: undefined}})`unicorns`).toBeAssignableTo<Result>();31expectTypeOf(await execa({env: {test: undefined} as const})`unicorns`).toBeAssignableTo<Result>();