Skip to content

Commit

Permalink
Constrain isConditionalParameter type parameter
Browse files Browse the repository at this point in the history
Fixes vega#8465
  • Loading branch information
fcollonval authored Oct 11, 2022
1 parent 93b4585 commit 800de0f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/channeldef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,23 @@ export type StringValueDefWithCondition<F extends Field, T extends Type = Standa
>;
export type TypeForShape = 'nominal' | 'ordinal' | 'geojson';

export type Conditional<CD extends FieldDef<any> | DatumDef | ValueDef<any> | ExprRef | SignalRef> =
export type ConditionalTemplate = FieldDef<any> | DatumDef | ValueDef<any> | ExprRef | SignalRef;

export type Conditional<CD extends ConditionalTemplate> =
| ConditionalPredicate<CD>
| ConditionalParameter<CD>;

export type ConditionalPredicate<CD extends FieldDef<any> | DatumDef | ValueDef<any> | ExprRef | SignalRef> = {
export type ConditionalPredicate<CD extends ConditionalTemplate> = {
/**
* Predicate for triggering the condition
*/
test: LogicalComposition<Predicate>;
} & CD;

export type ConditionalParameter<CD extends FieldDef<any> | DatumDef | ValueDef<any> | ExprRef | SignalRef> =
export type ConditionalParameter<CD extends ConditionalTemplate> =
ParameterPredicate & CD;

export function isConditionalParameter<T>(c: Conditional<T>): c is ConditionalParameter<T> {
export function isConditionalParameter<T extends ConditionalTemplate>(c: Conditional<T>): c is ConditionalParameter<T> {
return c['param'];
}

Expand Down

0 comments on commit 800de0f

Please sign in to comment.