From 0e22da7a59131145ce7624bdf41f1770ba3ff914 Mon Sep 17 00:00:00 2001 From: Sunny Hirai Date: Mon, 29 Mar 2021 09:29:32 -0700 Subject: [PATCH] Improved ExtendedType to limit extending only known custom types --- packages/slate/src/interfaces/custom-types.ts | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/packages/slate/src/interfaces/custom-types.ts b/packages/slate/src/interfaces/custom-types.ts index c8999cd38..397112a05 100644 --- a/packages/slate/src/interfaces/custom-types.ts +++ b/packages/slate/src/interfaces/custom-types.ts @@ -2,10 +2,28 @@ * Extendable Custom Types Interface */ +type ExtendableTypes = + | 'Editor' + | 'Element' + | 'Text' + | 'Selection' + | 'Range' + | 'Point' + | 'InsertNodeOperation' + | 'InsertTextOperation' + | 'MergeNodeOperation' + | 'MoveNodeOperation' + | 'RemoveNodeOperation' + | 'RemoveTextOperation' + | 'SetNodeOperation' + | 'SetSelectionOperation' + | 'SplitNodeOperation' + export interface CustomTypes { [key: string]: unknown } -export type ExtendedType = unknown extends CustomTypes[K] - ? B - : CustomTypes[K] +export type ExtendedType< + K extends ExtendableTypes, + B +> = unknown extends CustomTypes[K] ? B : CustomTypes[K]