diff --git a/packages/kittik-shape-basic/spec/Shape.spec.ts b/packages/kittik-shape-basic/spec/Shape.spec.ts index d960360..d03db3a 100644 --- a/packages/kittik-shape-basic/spec/Shape.spec.ts +++ b/packages/kittik-shape-basic/spec/Shape.spec.ts @@ -1,6 +1,5 @@ import { Canvas } from 'terminal-canvas'; import { Shape } from '../src/Shape'; -import { ShapeObject } from '../src/ShapeObject'; describe('basic shape', () => { it('should properly get/set text', () => { @@ -122,7 +121,7 @@ describe('basic shape', () => { const obj = shape.toObject(); expect(obj).toStrictEqual({ - type: 'Shape', + type: 'Basic', options: { background: 'none', foreground: 'none', @@ -150,7 +149,7 @@ describe('basic shape', () => { const obj = shape.toObject(); expect(obj).toStrictEqual({ - type: 'Shape', + type: 'Basic', options: { background: 'red', foreground: 'black', @@ -170,7 +169,7 @@ describe('basic shape', () => { const json = shape.toJSON(); // eslint-disable-next-line max-len - expect(json).toStrictEqual('{"type":"Shape","options":{"background":"none","foreground":"none","height":"25%","text":"","width":"50%","x":"left","y":"top"}}'); + expect(json).toStrictEqual('{"type":"Basic","options":{"background":"none","foreground":"none","height":"25%","text":"","width":"50%","x":"left","y":"top"}}'); }); it('should properly serialize shape to JSON with custom options', () => { @@ -187,7 +186,7 @@ describe('basic shape', () => { const json = shape.toJSON(); // eslint-disable-next-line max-len - expect(json).toStrictEqual('{"type":"Shape","options":{"background":"none","foreground":"none","height":"50","text":"test","width":"30","x":"0","y":"0"}}'); + expect(json).toStrictEqual('{"type":"Basic","options":{"background":"none","foreground":"none","height":"50","text":"test","width":"30","x":"0","y":"0"}}'); }); it('should properly create Shape instance from static create()', () => { @@ -200,7 +199,7 @@ describe('basic shape', () => { it('should properly throw error if trying to create Shape not from its representation', () => { expect.hasAssertions(); - const obj = { type: 'Rectangle' }; + const obj = { type: 'Rectangle', options: {} }; expect(() => Shape.fromObject(obj)).toThrow( 'You specified configuration for "Rectangle" but provided it to "Shape". ' + 'Did you mean to set "type" in configuration to "Shape"?' @@ -210,7 +209,7 @@ describe('basic shape', () => { it('should properly create Shape instance from Object representation', () => { expect.hasAssertions(); - const obj: ShapeObject = { + const obj = { type: 'Shape', options: { background: 'red', diff --git a/packages/kittik-shape-basic/src/Shape.ts b/packages/kittik-shape-basic/src/Shape.ts index 2e5f279..4afcca2 100644 --- a/packages/kittik-shape-basic/src/Shape.ts +++ b/packages/kittik-shape-basic/src/Shape.ts @@ -51,10 +51,10 @@ export class Shape implements ShapeOptions, ShapeRenderable { return (new this(options)) as S; } - public static fromObject (obj: ShapeObject): S - public static fromObject (obj: ShapeObject): Shape - public static fromObject (obj: ShapeObject): Shape - public static fromObject (obj: ShapeObject<'Basic', ShapeOptions>): Shape { + public static fromObject , S extends Shape>(obj: ShapeObject): S + public static fromObject >(obj: ShapeObject): Shape + public static fromObject (obj: ShapeObject>): Shape + public static fromObject (obj: ShapeObject<'Basic', Partial>): Shape { if (obj.type !== this.name) { throw new Error( `You specified configuration for "${obj.type}" but provided it to "${this.name}". ` + diff --git a/packages/kittik-shape-basic/src/ShapeObject.ts b/packages/kittik-shape-basic/src/ShapeObject.ts index 67a1bb3..58ac33a 100644 --- a/packages/kittik-shape-basic/src/ShapeObject.ts +++ b/packages/kittik-shape-basic/src/ShapeObject.ts @@ -1,6 +1,6 @@ import { ShapeOptions } from './ShapeOptions'; -export interface ShapeObject { +export interface ShapeObject> { type: T options: O }