Typed variables pt6: Clean up and test variable type guards (take 2) (#54025)

* Add fixture-factories for all variable types

* clean up variable guards

* add tests for isMulti, hasCurrent, and hasOptions variable type guards

* create VariableSupport type to try and work around ts wonkiness
This commit is contained in:
Josh Hunt
2022-08-22 14:45:40 +01:00
committed by GitHub
parent 4c8ea0bb89
commit 9db9ebce02
5 changed files with 189 additions and 39 deletions
@@ -173,6 +173,13 @@ export interface DataSourceConstructor<
new (instanceSettings: DataSourceInstanceSettings<TOptions>, ...args: any[]): DSType;
}
// VariableSupport is hoisted up to its own type to fix the wonky intermittent
// 'variables is references directly or indirectly' error
type VariableSupport<TQuery extends DataQuery, TOptions extends DataSourceJsonData> =
| StandardVariableSupport<DataSourceApi<TQuery, TOptions>>
| CustomVariableSupport<DataSourceApi<TQuery, TOptions>>
| DataSourceVariableSupport<DataSourceApi<TQuery, TOptions>>;
/**
* The main data source abstraction interface, represents an instance of a data source
*
@@ -341,10 +348,7 @@ abstract class DataSourceApi<
* Defines new variable support
* @alpha -- experimental
*/
variables?:
| StandardVariableSupport<DataSourceApi<TQuery, TOptions>>
| CustomVariableSupport<DataSourceApi<TQuery, TOptions>>
| DataSourceVariableSupport<DataSourceApi<TQuery, TOptions>>;
variables?: VariableSupport<TQuery, TOptions>;
/*
* Optionally, use this method to set default values for a query