Skip to main content
Module

x/ts_toolbelt_unofficial/mod.ts>F.Narrow

👷 TypeScript's largest type utility library, now on Deno
Latest
type alias F.Narrow
import { type F } from "https://deno.land/x/ts_toolbelt_unofficial@1.1.0/mod.ts";
const { Narrow } = F;

Prevent type widening on generic function parameters

Examples

Example 1

import {F} from 'ts-toolbelt.ts'

declare function foo<A extends any[]>(x: F.Narrow<A>): A;
declare function bar<A extends object>(x: F.Narrow<A>): A;

const test0 = foo(['e', 2, true, {f: ['g', ['h']]}])
// `A` inferred : ['e', 2, true, {f: ['g']}]

const test1 = bar({a: 1, b: 'c', d: ['e', 2, true, {f: ['g']}]})
// `A` inferred : {a: 1, b: 'c', d: ['e', 2, true, {f: ['g']}]}

Type Parameters

A extends any
definition: Try<A, [], NarrowRaw<A>>