graceguo-supercat commented on a change in pull request #9820:
URL:
https://github.com/apache/incubator-superset/pull/9820#discussion_r427683963
##########
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:
yes, i feel `parentDepth` should be `number` type. This intermediate
step a little confused me. Thanks!
----------------------------------------------------------------
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]