11import EditorModel from '../editor/model/Editor' ;
22import { DataComponentTypes , DataResolver , DataResolverProps , ResolverFromProps } from './types' ;
33import { DataCollectionStateMap } from './model/data_collection/types' ;
4- import { DataConditionType , DataCondition } from './model/conditional_variables/DataCondition' ;
4+ import { DataConditionType , DataCondition , DataConditionProps } from './model/conditional_variables/DataCondition' ;
55import DataVariable , { DataVariableProps , DataVariableType } from './model/DataVariable' ;
66import { ComponentDefinition , ComponentOptions } from '../dom_components/model/types' ;
77import { serialize } from '../utils/mixins' ;
@@ -10,20 +10,26 @@ import Component from '../dom_components/model/Component';
1010
1111export const DEF_DATA_FIELD_ID = 'id' ;
1212
13- export function isDataResolverProps ( value : any ) : value is DataResolverProps {
14- return typeof value === 'object' && [ DataVariableType , DataConditionType ] . includes ( value ?. type ) ;
13+ type DataVariableTypedProps = DataVariableProps & { type : typeof DataVariableType } ;
14+ type DataConditionTypedProps = DataConditionProps & { type : typeof DataConditionType } ;
15+ type DataResolverTypedProps = DataVariableTypedProps | DataConditionTypedProps ;
16+
17+ const isTypedObject = ( value : unknown ) : value is { type ?: unknown } => typeof value === 'object' && value !== null ;
18+
19+ export function isDataResolverProps ( value : unknown ) : value is DataResolverTypedProps {
20+ return isTypedObject ( value ) && ( value . type === DataVariableType || value . type === DataConditionType ) ;
1521}
1622
17- export function isDataResolver ( value : any ) : value is DataResolver {
23+ export function isDataResolver ( value : unknown ) : value is DataResolver {
1824 return value instanceof DataVariable || value instanceof DataCondition ;
1925}
2026
21- export function isDataVariable ( variable : any ) : variable is DataVariableProps {
22- return variable ? .type === DataVariableType ;
27+ export function isDataVariable ( variable : unknown ) : variable is DataVariableTypedProps {
28+ return isTypedObject ( variable ) && variable . type === DataVariableType ;
2329}
2430
25- export function isDataCondition ( variable : any ) {
26- return variable ? .type === DataConditionType ;
31+ export function isDataCondition ( variable : unknown ) : variable is DataConditionTypedProps {
32+ return isTypedObject ( variable ) && variable . type === DataConditionType ;
2733}
2834
2935export function valueOrResolve ( variable : any , opts : { em : EditorModel ; collectionsStateMap : DataCollectionStateMap } ) {
0 commit comments