Skip to content

Instantly share code, notes, and snippets.

@temoncher
Last active October 27, 2022 11:10
Show Gist options
  • Select an option

  • Save temoncher/d813bce892e5b4d52763cedccc4a22d2 to your computer and use it in GitHub Desktop.

Select an option

Save temoncher/d813bce892e5b4d52763cedccc4a22d2 to your computer and use it in GitHub Desktop.
Typed String.prototype.includes
type FilterUnion<T extends string, Keys extends string> = {
[Key in Keys extends infer R ? (R extends `${string}${T}${string}` ? R : never) : never]: string;
} extends infer O
? keyof O
: never;
export const stringIncludes = <T extends string>(text: T) => <S extends string>(
str: S
): str is FilterUnion<T, S> => str.includes(text);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment