ChristianMurphy commented on a change in pull request #9820:
URL:
https://github.com/apache/incubator-superset/pull/9820#discussion_r427652631
##########
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:
It depends, I aimed to keep the behavior the same, taking in an unknown
and returning a known type.
This entire function could theoretically be completely removed, using a
combo of keyof and generics can statically check most of this:
```
interface ValidChild<
P extends keyof ParentMaxDepthLookup,
C extends keyof ParentMaxDepthLookup[P],
D extends ParentMaxDepthLookup[P][C]
> {
parentType: P;
childType: C;
parentDepth: D;
}
```
---
as an intermediate step, I could set `parentDepth` to be number and remove
this check.
thoughts? :thought_balloon:
can check all three statically.
##########
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:
It depends, I aimed to keep the behavior the same, taking in an unknown
and returning a known type.
This entire function could theoretically be completely removed, using a
combo of keyof and generics can statically check most of this:
```ts
interface ValidChild<
P extends keyof ParentMaxDepthLookup,
C extends keyof ParentMaxDepthLookup[P],
D extends ParentMaxDepthLookup[P][C]
> {
parentType: P;
childType: C;
parentDepth: D;
}
```
---
as an intermediate step, I could set `parentDepth` to be number and remove
this check.
thoughts? :thought_balloon:
can check all three statically.
##########
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:
It depends, I aimed to keep the behavior the same, taking in an unknown
and returning a known type.
This entire function could theoretically be completely removed, using a
combo of keyof and generics can statically check most of this:
```ts
interface ValidChild<
P extends keyof ParentMaxDepthLookup,
C extends keyof ParentMaxDepthLookup[P],
D extends ParentMaxDepthLookup[P][C]
> {
parentType: P;
childType: C;
parentDepth: D;
}
```
---
as an intermediate step, I could set `parentDepth` to be number and remove
this check.
thoughts? :thought_balloon:
----------------------------------------------------------------
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]