Skip to content

Commit

Permalink
Simplify types
Browse files Browse the repository at this point in the history
  • Loading branch information
ilia-db committed Sep 23, 2024
1 parent 9680378 commit 23ac0f4
Showing 1 changed file with 7 additions and 28 deletions.
35 changes: 7 additions & 28 deletions packages/databricks-vscode/src/bundle/types.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,19 @@
import {BundleSchema as OriginalBundleSchema} from "./BundleSchema";

type RemoveStringFromUnion<T> = T extends string ? never : T;

type RemoveStringFromType<T> = T extends object
type RemoveStringFromUnionTypes<T> = T extends object
? {
[K in keyof T]: T[K] extends string | undefined
? T[K]
: RemoveStringFromType<T[K]>;
: RemoveStringFromUnionTypes<T[K]>;
}
: RemoveStringFromUnion<T>;

export type BundleTarget = Omit<
RemoveStringFromType<Required<OriginalBundleSchema>>["targets"][string],
"variables"
> & {
// Use custom override for in-target variable type, because CLI < v0.215.0
// uses the same class for both in-target and global variables.
// TODO: Remove this override when fixed in CLI (> v0.215.0).
variables?: {
[k: string]: (
| string
| Required<
RemoveStringFromType<
Required<OriginalBundleSchema>
>["variables"][string]
>["lookup"]
) & {value?: string};
};
};

export type BundleSchema = Omit<
RemoveStringFromType<OriginalBundleSchema>,
"targets"
> & {
targets?: {[k: string]: BundleTarget};
};
// CLI generates schema with additional string types added for almost complex sub types (to support complex variables).
// We usually work with `bundle validate` or `summary` outputs, which have expanded variables, so we don't need
// to account for additional string types.
export type BundleSchema = RemoveStringFromUnionTypes<OriginalBundleSchema>;
export type BundleTarget = Required<BundleSchema>["targets"][string];

export type Resources<T> = T extends {resources?: infer D} ? D : never;
export type ResourceKey<T> = keyof Resources<T>;
Expand Down

0 comments on commit 23ac0f4

Please sign in to comment.