Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/fonction/common/mod.ts>Head

A modern practical functional library
Latest
type alias Head
import { type Head } from "https://deno.land/x/fonction@v2.1.0-beta.4/common/mod.ts";

Infer the head types.

Examples

Example 1

// String
Head<string> // string
Head<''> // ''
Head<'hello'> // 'h'

Example 2

// Array
Head<[] | never[] | readonly [] | readonly never[]> // undefined
Head<['hello', 'world']> // 'hello'
Head<string | number[]> // string | number | undefined

Type Parameters

T extends readonly unknown[] | string
definition: T extends string ? T extends `${infer F}${string}` ? F : T extends "" ? "" : string : T extends readonly [infer U, ...infer _] ? U : T[0] | undefined