Last active
October 27, 2022 11:10
-
-
Save temoncher/d813bce892e5b4d52763cedccc4a22d2 to your computer and use it in GitHub Desktop.
Typed String.prototype.includes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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