Skip to content

Commit

Permalink
fix: 🐛 animation options are mandatory on creating animations
Browse files Browse the repository at this point in the history
When creating animation from object declarations or options, all the
fields of these options were required. This commit looses the contract
by applying Partial over these types.
  • Loading branch information
ghaiklor committed Apr 26, 2020
1 parent ba02210 commit 52665f7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions packages/kittik-animation-basic/src/animation/Animation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ export class Animation extends EventEmitter implements AnimationOptions {
this.on('tick', this.onTick.bind(this));
}

public static create <A extends Animation, O extends AnimationOptions>(options: O): A
public static create <O extends AnimationOptions>(options: O): Animation
public static create (options: AnimationOptions): Animation {
public static create <A extends Animation, O extends Partial<AnimationOptions>>(options: O): A
public static create <O extends Partial<AnimationOptions>>(options: O): Animation
public static create (options: Partial<AnimationOptions>): Animation {
return new this(options);
}

public static fromObject <T, O extends AnimationOptions, A extends Animation>(obj: AnimationObject<T, O>): A
public static fromObject <T, O extends AnimationOptions>(obj: AnimationObject<T, O>): Animation
public static fromObject <T>(obj: AnimationObject<T, AnimationOptions>): Animation
public static fromObject (obj: AnimationObject<'Basic', AnimationOptions>): Animation {
public static fromObject <T, O extends Partial<AnimationOptions>, A extends Animation>(obj: AnimationObject<T, O>): A
public static fromObject <T, O extends Partial<AnimationOptions>>(obj: AnimationObject<T, O>): Animation
public static fromObject <T>(obj: AnimationObject<T, Partial<AnimationOptions>>): Animation
public static fromObject (obj: AnimationObject<'Basic', Partial<AnimationOptions>>): Animation {
if (obj.type !== this.name) {
throw new Error(
`You specified configuration for "${obj.type}" but provided it to "${this.name}". ` +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AnimationOptions } from './AnimationOptions';

export interface AnimationObject<T, O extends AnimationOptions> {
export interface AnimationObject<T, O extends Partial<AnimationOptions>> {
type: T
options: O
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AnimationOptions, AnimationType } from './Animations';
import { AnimationObject } from 'kittik-animation-basic';

export interface AnimationDeclaration extends AnimationObject<AnimationType, AnimationOptions<AnimationType>> {
export interface AnimationDeclaration extends AnimationObject<AnimationType, Partial<AnimationOptions<AnimationType>>> {
name: string
}
2 changes: 1 addition & 1 deletion packages/kittik-slide/src/shape/ShapeDeclaration.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ShapeOptions, ShapeType } from './Shapes';
import { ShapeObject } from 'kittik-shape-basic';

export interface ShapeDeclaration extends ShapeObject<ShapeType, ShapeOptions<ShapeType>> {
export interface ShapeDeclaration extends ShapeObject<ShapeType, Partial<ShapeOptions<ShapeType>>> {
name: string
}

0 comments on commit 52665f7

Please sign in to comment.