From e473e4b641c6f2d92ffaa1210d0ddc4b01a45f54 Mon Sep 17 00:00:00 2001 From: Kir_Antipov Date: Mon, 26 Dec 2022 08:16:10 +0000 Subject: [PATCH] Made a type to help me use generics as record keys --- src/utils/types/record-key.ts | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/utils/types/record-key.ts diff --git a/src/utils/types/record-key.ts b/src/utils/types/record-key.ts new file mode 100644 index 0000000..4006f3e --- /dev/null +++ b/src/utils/types/record-key.ts @@ -0,0 +1,8 @@ +/** + * Returns `T` if it extends `PropertyKey`; otherwise, returns `never`. + * + * This is useful to lift the constraints from a record key. + * + * @template T - The type to check if it extends `PropertyKey`. + */ +export type RecordKey = T extends PropertyKey ? T : never;