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
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']}]}