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



##########
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> {
+  const { parentType, childType, parentDepth } = child;
   if (!parentType || !childType || typeof parentDepth !== 'number') {

Review comment:
       since we use TypeScript, is type check here still necessary?




----------------------------------------------------------------
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