From 13c308f2dfeb0968f749d26aeec8125d8852c30e Mon Sep 17 00:00:00 2001 From: tommy-mitchell Date: Mon, 6 Mar 2023 18:16:28 -0600 Subject: [PATCH] feat: `IsStringLiteral` documentation --- source/is-literal.d.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/source/is-literal.d.ts b/source/is-literal.d.ts index 4cba221c6..c93c20832 100644 --- a/source/is-literal.d.ts +++ b/source/is-literal.d.ts @@ -24,10 +24,20 @@ type LiteralChecks = ( /** Returns a boolean for whether the given type is a `string` [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types). +Useful for constraining strings to be a string literal, or for providing strongly-typed string manipulation functions. + @example ``` import type {IsStringLiteral} from 'type-fest'; +type CapitalizedString = IsStringLiteral extends true ? Capitalize : string; + +function capitalize>(input: T): CapitalizedString { + return (input.slice(0, 1).toUpperCase() + input.slice(1)) as CapitalizedString; +} + +const output = capitalize('hello, world!'); +//=> 'Hello, world!' ``` @category Utilities