From d749be11f08008b2e020af6bbeb82d635e5fb239 Mon Sep 17 00:00:00 2001 From: Alexander Rose <alexander.rose@weirdbyte.de> Date: Sun, 11 Sep 2022 14:34:21 -0700 Subject: [PATCH] type fixes --- .../builder/structure/representation.ts | 2 +- src/mol-plugin-state/component.ts | 2 +- src/mol-plugin-state/formats/trajectory.ts | 2 +- src/mol-plugin-ui/base.tsx | 2 +- src/mol-plugin/behavior/behavior.ts | 6 +++--- src/mol-state/action.ts | 4 ++-- src/mol-state/transformer.ts | 4 ++-- src/mol-util/index.ts | 6 +++--- src/mol-util/object.ts | 10 +++++----- src/mol-util/param-definition.ts | 2 +- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/mol-plugin-state/builder/structure/representation.ts b/src/mol-plugin-state/builder/structure/representation.ts index fc2b05c02..4bcbb6861 100644 --- a/src/mol-plugin-state/builder/structure/representation.ts +++ b/src/mol-plugin-state/builder/structure/representation.ts @@ -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); diff --git a/src/mol-plugin-state/component.ts b/src/mol-plugin-state/component.ts index 8230b7f22..46b7c3507 100644 --- a/src/mol-plugin-state/component.ts +++ b/src/mol-plugin-state/component.ts @@ -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 { diff --git a/src/mol-plugin-state/formats/trajectory.ts b/src/mol-plugin-state/formats/trajectory.ts index c8eca7e90..82eef8708 100644 --- a/src/mol-plugin-state/formats/trajectory.ts +++ b/src/mol-plugin-state/formats/trajectory.ts @@ -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) diff --git a/src/mol-plugin-ui/base.tsx b/src/mol-plugin-ui/base.tsx index 6311d351b..6d724fa66 100644 --- a/src/mol-plugin-ui/base.tsx +++ b/src/mol-plugin-ui/base.tsx @@ -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; diff --git a/src/mol-plugin/behavior/behavior.ts b/src/mol-plugin/behavior/behavior.ts index ddbb603c3..96ada468b 100644 --- a/src/mol-plugin/behavior/behavior.ts +++ b/src/mol-plugin/behavior/behavior.ts @@ -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)); diff --git a/src/mol-state/action.ts b/src/mol-state/action.ts index b6416e63f..864a8cb95 100644 --- a/src/mol-state/action.ts +++ b/src/mol-state/action.ts @@ -84,7 +84,7 @@ namespace StateAction { } export namespace Builder { - export interface Type<A extends StateObject.Ctor, P extends { }> { + export interface Type<A extends StateObject.Ctor, P extends {}> { from?: A | A[], params?: PD.For<P> | ((a: StateObject.From<A>, globalCtx: any) => PD.For<P>), display?: string | { name: string, description?: string }, @@ -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>, } diff --git a/src/mol-state/transformer.ts b/src/mol-state/transformer.ts index 0656babb8..94905d9af 100644 --- a/src/mol-state/transformer.ts +++ b/src/mol-state/transformer.ts @@ -196,7 +196,7 @@ namespace Transformer { } export namespace Builder { - export interface Type<A extends StateObject.Ctor, B extends StateObject.Ctor, P extends { }> { + export interface Type<A extends StateObject.Ctor, B extends StateObject.Ctor, P extends {}> { name: string, from: A | A[], to: B | B[], @@ -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> } diff --git a/src/mol-util/index.ts b/src/mol-util/index.ts index 4db05201c..ba4d557c3 100644 --- a/src/mol-util/index.ts +++ b/src/mol-util/index.ts @@ -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; diff --git a/src/mol-util/object.ts b/src/mol-util/object.ts index d11c4bb9e..1cdbe8e9e 100644 --- a/src/mol-util/object.ts +++ b/src/mol-util/object.ts @@ -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; diff --git a/src/mol-util/param-definition.ts b/src/mol-util/param-definition.ts index 46840b54a..a9697f5f4 100644 --- a/src/mol-util/param-definition.ts +++ b/src/mol-util/param-definition.ts @@ -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); } -- GitLab