Skip to content
Snippets Groups Projects
Commit d749be11 authored by Alexander Rose's avatar Alexander Rose
Browse files

type fixes

parent 13dc9ff3
No related branches found
No related tags found
No related merge requests found
......@@ -90,7 +90,7 @@ export class StructureRepresentationBuilder {
}
applyPreset<K extends keyof PresetStructureRepresentations>(parent: StateObjectRef<PluginStateObject.Molecule.Structure>, preset: K, params?: StructureRepresentationPresetProvider.Params<PresetStructureRepresentations[K]>): Promise<StructureRepresentationPresetProvider.State<PresetStructureRepresentations[K]>> | undefined
applyPreset<P = any, S = {}>(parent: StateObjectRef<PluginStateObject.Molecule.Structure>, provider: StructureRepresentationPresetProvider<P, S>, params?: P): Promise<S> | undefined
applyPreset<P = any, S extends {} = {}>(parent: StateObjectRef<PluginStateObject.Molecule.Structure>, provider: StructureRepresentationPresetProvider<P, S>, params?: P): Promise<S> | undefined
applyPreset(parent: StateObjectRef<PluginStateObject.Molecule.Structure>, providerId: string, params?: any): Promise<any> | undefined
applyPreset(parent: StateObjectRef, providerRef: string | StructureRepresentationPresetProvider, params?: any): Promise<any> | undefined {
const provider = this.resolveProvider(providerRef);
......
......@@ -42,7 +42,7 @@ export class PluginComponent {
}
}
export class StatefulPluginComponent<State> extends PluginComponent {
export class StatefulPluginComponent<State extends {}> extends PluginComponent {
private _state: State;
protected updateState(...states: Partial<State>[]): boolean {
......
......@@ -75,7 +75,7 @@ export const CifCoreProvider: TrajectoryFormatProvider = {
visuals: defaultVisuals
};
function directTrajectory<P>(transformer: StateTransformer<PluginStateObject.Data.String | PluginStateObject.Data.Binary, PluginStateObject.Molecule.Trajectory, P>, transformerParams?: P): TrajectoryFormatProvider['parse'] {
function directTrajectory<P extends {}>(transformer: StateTransformer<PluginStateObject.Data.String | PluginStateObject.Data.Binary, PluginStateObject.Molecule.Trajectory, P>, transformerParams?: P): TrajectoryFormatProvider['parse'] {
return async (plugin, data, params) => {
const state = plugin.state.data;
const trajectory = await state.build().to(data)
......
......@@ -13,7 +13,7 @@ import { Icon, ArrowRightSvg, ArrowDropDownSvg } from './controls/icons';
export const PluginReactContext = React.createContext(void 0 as any as PluginUIContext);
export abstract class PluginUIComponent<P = {}, S = {}, SS = {}> extends React.Component<P & { children?: any }, S, SS> {
export abstract class PluginUIComponent<P extends {} = {}, S = {}, SS = {}> extends React.Component<P & { children?: any }, S, SS> {
static contextType = PluginReactContext;
readonly plugin: PluginUIContext;
......
......@@ -40,7 +40,7 @@ namespace PluginBehavior {
'misc': 'Miscellaneous'
};
export interface CreateParams<P> {
export interface CreateParams<P extends {}> {
name: string,
category: keyof typeof Categories,
ctor: Ctor<P>,
......@@ -73,7 +73,7 @@ namespace PluginBehavior {
return categoryMap.get(t.id)!;
}
export function create<P>(params: CreateParams<P>) {
export function create<P extends {}>(params: CreateParams<P>) {
const t = PluginStateTransform.CreateBuiltIn<Category, Behavior, P>({
name: params.name,
display: params.display,
......@@ -113,7 +113,7 @@ namespace PluginBehavior {
};
}
export abstract class Handler<P = { }> implements PluginBehavior<P> {
export abstract class Handler<P extends {} = {}> implements PluginBehavior<P> {
private subs: PluginCommand.Subscription[] = [];
protected subscribeCommand<T>(cmd: PluginCommand<T>, action: PluginCommand.Action<T>) {
this.subs.push(cmd.subscribe(this.ctx, action));
......
......@@ -95,7 +95,7 @@ namespace StateAction {
<A extends StateObject.Ctor, P extends { }>(info: Type<A, P>): Define<StateObject.From<A>, PD.Normalize<P>>
}
export interface Define<A extends StateObject, P> {
export interface Define<A extends StateObject, P extends {}> {
<T>(def: DefinitionBase<A, T, P> | DefinitionBase<A, T, P>['run']): StateAction<A, T, P>,
}
......
......@@ -210,7 +210,7 @@ namespace Transformer {
<A extends StateObject.Ctor, B extends StateObject.Ctor, P extends { }>(info: Type<A, B, P>): Define<StateObject.From<A>, StateObject.From<B>, PD.Normalize<P>>
}
export interface Define<A extends StateObject, B extends StateObject, P> {
export interface Define<A extends StateObject, B extends StateObject, P extends {}> {
(def: DefinitionBase<A, B, P>): Transformer<A, B, P>
}
......
......@@ -117,7 +117,7 @@ export function defaults<T>(value: T | undefined, defaultValue: T): T {
return value !== undefined ? value : defaultValue;
}
export function extend<S, T, U>(object: S, source: T, guard?: U): S & T & U {
export function extend<S extends {}, T extends {}, U extends {}>(object: S, source: T, guard?: U): S & T & U {
let v: any;
const s = <any>source;
......@@ -139,7 +139,7 @@ export function extend<S, T, U>(object: S, source: T, guard?: U): S & T & U {
return <any>object;
}
export function shallowClone<T>(o: T): T {
export function shallowClone<T extends {}>(o: T): T {
return extend({}, o) as T;
}
......@@ -158,7 +158,7 @@ function _assign<T>(target: T): T {
export declare function _assignType<T>(o: T, ...from: any[]): T;
export const assign: (<T>(o: T, ...from: any[]) => T) = (Object as any).assign || _assign;
function _shallowMerge1<T>(source: T, update: T) {
function _shallowMerge1<T extends {}>(source: T, update: T) {
let changed = false;
for (const k of Object.keys(update)) {
if (!hasOwnProperty.call(update, k)) continue;
......
......@@ -8,7 +8,7 @@
const hasOwnProperty = Object.prototype.hasOwnProperty;
/** Assign to the object if a given property in update is undefined */
export function assignIfUndefined<T>(to: Partial<T>, full: T): T {
export function assignIfUndefined<T extends {}>(to: Partial<T>, full: T): T {
for (const k of Object.keys(full)) {
if (!hasOwnProperty.call(full, k)) continue;
......@@ -20,7 +20,7 @@ export function assignIfUndefined<T>(to: Partial<T>, full: T): T {
}
/** Create new object if any property in "update" changes in "source". */
export function shallowMerge2<T>(source: T, update: Partial<T>): T {
export function shallowMerge2<T extends {}>(source: T, update: Partial<T>): T {
// Adapted from LiteMol (https://github.com/dsehnal/LiteMol)
let changed = false;
for (const k of Object.keys(update)) {
......@@ -36,7 +36,7 @@ export function shallowMerge2<T>(source: T, update: Partial<T>): T {
return Object.assign({}, source, update);
}
export function shallowEqual<T>(a: T, b: T) {
export function shallowEqual<T extends {}>(a: T, b: T) {
if (!a) {
if (!b) return true;
return false;
......@@ -52,11 +52,11 @@ export function shallowEqual<T>(a: T, b: T) {
return true;
}
export function shallowMerge<T>(source: T, ...rest: (Partial<T> | undefined)[]): T {
export function shallowMerge<T extends {}>(source: T, ...rest: (Partial<T> | undefined)[]): T {
return shallowMergeArray(source, rest);
}
export function shallowMergeArray<T>(source: T, rest: (Partial<T> | undefined)[]): T {
export function shallowMergeArray<T extends {}>(source: T, rest: (Partial<T> | undefined)[]): T {
// Adapted from LiteMol (https://github.com/dsehnal/LiteMol)
let ret: any = source;
......
......@@ -324,7 +324,7 @@ export namespace ParamDefinition {
conditionForValue(v: T): keyof C
conditionedValue(v: T, condition: keyof C): T,
}
export function Conditioned<T, P extends Base<T>, C = { [k: string]: P }>(defaultValue: T, conditionParams: C, conditionForValue: (v: T) => keyof C, conditionedValue: (v: T, condition: keyof C) => T, info?: Info): Conditioned<T, P, C> {
export function Conditioned<T, P extends Base<T>, C extends {} = { [k: string]: P }>(defaultValue: T, conditionParams: C, conditionForValue: (v: T) => keyof C, conditionedValue: (v: T, condition: keyof C) => T, info?: Info): Conditioned<T, P, C> {
const options = Object.keys(conditionParams).map(k => [k, k]) as [string, string][];
return setInfo({ type: 'conditioned', select: Select<string>(conditionForValue(defaultValue) as string, options, info), defaultValue, conditionParams, conditionForValue, conditionedValue }, info);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment