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

x/fonction/common/last.ts>Last

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

Infer the last types.

Examples

Example 1

// String
Last<string> // string
Last<''> // ''
Last<'hello'> // 'o'

Example 2

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

Type Parameters

T extends string | readonly unknown[]
definition: T extends string ? LastString<T> : T extends readonly [...infer _, infer L] ? L : T[T["length"]] | undefined