ChristianMurphy commented on a change in pull request #9820:
URL: 
https://github.com/apache/incubator-superset/pull/9820#discussion_r426219981



##########
File path: superset-frontend/src/dashboard/util/isValidChild.ts
##########
@@ -105,12 +105,36 @@ const parentMaxDepthLookup = {
   [MARKDOWN_TYPE]: {},
 };
 
-export default function isValidChild({ parentType, childType, parentDepth }) {
+type ParentMaxDepthLookup = typeof parentMaxDepthLookup;
+
+interface IsValidChildProps {
+  parentType?: unknown;
+  childType?: unknown;
+  parentDepth?: unknown;
+}
+
+interface ValidChild<
+  P extends keyof ParentMaxDepthLookup,
+  C extends keyof ParentMaxDepthLookup[P],
+  D extends ParentMaxDepthLookup[P][C]
+> {
+  parentType: P;
+  childType: C;
+  parentDepth: D;
+}
+
+export default function isValidChild<
+  P extends keyof ParentMaxDepthLookup = any,
+  C extends keyof ParentMaxDepthLookup[P] = any,
+  D extends ParentMaxDepthLookup[P][C] = any
+>(child: IsValidChildProps): child is ValidChild<P, C, D> {

Review comment:
       The idea here is to offer a version which doesn't need the generics 
(falling back to any).
   but if generics are provided, it can apply a predicate to narrow the type 
https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to