Skip to content
Myr

generator-widened.test-d.ts

This file

Path

test-d/stdio/option/generator-widened.test-d.ts

45 lines · 1.4 KiB · TypeScript

Last changed by

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

History of this file

Take it

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

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

Type the `std*` generator transform `chunk` argument (#1247)Sindre Sorhusbefore adoption0a7b4f8

lines 2–17why, one step back
2import {
3 type StdinOption,4 type StdinSyncOption,5 type StdoutStderrOption,6 type StdoutStderrSyncOption,7} from '../../../index.js';89// Without `as const`, `binary`/`objectMode` widen to `boolean`. Since the transform mode is unknown at compile time, the `chunk` argument must be `unknown`.1011const widenedBinary = {12 * transform(line: unknown) {13 yield line;14 },15 binary: true,16};17

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

lines 18–21why, one step back
18expectTypeOf(widenedBinary).toBeAssignableTo<StdinOption>();
19expectTypeOf(widenedBinary).toBeAssignableTo<StdinSyncOption>();20expectTypeOf(widenedBinary).toBeAssignableTo<StdoutStderrOption>();21expectTypeOf(widenedBinary).toBeAssignableTo<StdoutStderrSyncOption>();

Type the `std*` generator transform `chunk` argument (#1247)Sindre Sorhusbefore adoption0a7b4f8

lines 22–29why, one step back
22
23const widenedObjectMode = {24 * transform(line: unknown) {25 yield line;26 },27 objectMode: true,28};29

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

lines 30–33why, one step back
30expectTypeOf(widenedObjectMode).toBeAssignableTo<StdinOption>();
31expectTypeOf(widenedObjectMode).toBeAssignableTo<StdinSyncOption>();32expectTypeOf(widenedObjectMode).toBeAssignableTo<StdoutStderrOption>();33expectTypeOf(widenedObjectMode).toBeAssignableTo<StdoutStderrSyncOption>();

Type the `std*` generator transform `chunk` argument (#1247)Sindre Sorhusbefore adoption0a7b4f8

lines 34–41why, one step back
34
35const widenedBinaryString = {36 * transform(line: string) {37 yield line;38 },39 binary: true,40};41

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

lines 42–45why, one step back
42expectTypeOf(widenedBinaryString).not.toBeAssignableTo<StdinOption>();
43expectTypeOf(widenedBinaryString).not.toBeAssignableTo<StdinSyncOption>();44expectTypeOf(widenedBinaryString).not.toBeAssignableTo<StdoutStderrOption>();45expectTypeOf(widenedBinaryString).not.toBeAssignableTo<StdoutStderrSyncOption>();