From 257d851fbd19e8e28f9ac4c285f71b87f8728e5c Mon Sep 17 00:00:00 2001 From: Leonard Thieu Date: Fri, 30 Jun 2017 13:32:57 -0400 Subject: [PATCH] [semantic-ui-shape] Different weak-type workaround. --- types/semantic-ui-shape/global.d.ts | 46 +++++++++---- .../semantic-ui-shape-tests.ts | 64 ++++++++++--------- 2 files changed, 69 insertions(+), 41 deletions(-) diff --git a/types/semantic-ui-shape/global.d.ts b/types/semantic-ui-shape/global.d.ts index cfd6cc689e..37bdcc5af7 100644 --- a/types/semantic-ui-shape/global.d.ts +++ b/types/semantic-ui-shape/global.d.ts @@ -83,19 +83,33 @@ declare namespace SemanticUI { */ (behavior: 'get transform down'): Shape.Translation; (behavior: 'destroy'): JQuery; - (behavior: 'setting', name: K, value?: undefined): ShapeSettings[K]; - (behavior: 'setting', name: K, value: ShapeSettings[K]): JQuery; - (behavior: 'setting', value: ShapeSettings.Param): JQuery; - (settings?: ShapeSettings.Param): JQuery; + (behavior: 'setting', name: K, value?: undefined): ShapeSettings._Impl[K]; + (behavior: 'setting', name: K, value: ShapeSettings._Impl[K]): JQuery; + (behavior: 'setting', value: ShapeSettings): JQuery; + (settings?: ShapeSettings): JQuery; } /** * @see {@link http://semantic-ui.com/modules/shape.html#/settings} */ - interface ShapeSettings extends Pick { } + type ShapeSettings = ShapeSettings.Param; namespace ShapeSettings { - type Param = ShapeSettings | object; + type Param = (Pick<_Impl, 'duration'> | + Pick<_Impl, 'width'> | + Pick<_Impl, 'height'> | + Pick<_Impl, 'beforeChange'> | + Pick<_Impl, 'onChange'> | + Pick<_Impl, 'selector'> | + Pick<_Impl, 'className'> | + Pick<_Impl, 'error'> | + Pick<_Impl, 'namespace'> | + Pick<_Impl, 'name'> | + Pick<_Impl, 'silent'> | + Pick<_Impl, 'debug'> | + Pick<_Impl, 'performance'> | + Pick<_Impl, 'verbose'>) & + Partial>; interface _Impl { // region Shape Settings @@ -198,10 +212,12 @@ declare namespace SemanticUI { transform: string; } - interface SelectorSettings extends Pick { } + type SelectorSettings = SelectorSettings.Param; namespace SelectorSettings { - type Param = SelectorSettings | object; + type Param = (Pick<_Impl, 'sides'> | + Pick<_Impl, 'side'>) & + Partial>; interface _Impl { /** @@ -215,10 +231,14 @@ declare namespace SemanticUI { } } - interface ClassNameSettings extends Pick { } + type ClassNameSettings = ClassNameSettings.Param; namespace ClassNameSettings { - type Param = ClassNameSettings | object; + type Param = (Pick<_Impl, 'animating'> | + Pick<_Impl, 'hidden'> | + Pick<_Impl, 'loading'> | + Pick<_Impl, 'active'>) & + Partial>; interface _Impl { /** @@ -240,10 +260,12 @@ declare namespace SemanticUI { } } - interface ErrorSettings extends Pick { } + type ErrorSettings = ErrorSettings.Param; namespace ErrorSettings { - type Param = ErrorSettings | object; + type Param = (Pick<_Impl, 'side'> | + Pick<_Impl, 'method'>) & + Partial>; interface _Impl { /** diff --git a/types/semantic-ui-shape/semantic-ui-shape-tests.ts b/types/semantic-ui-shape/semantic-ui-shape-tests.ts index 994909085a..92cb5e6bef 100644 --- a/types/semantic-ui-shape/semantic-ui-shape-tests.ts +++ b/types/semantic-ui-shape/semantic-ui-shape-tests.ts @@ -1,5 +1,5 @@ function test_shape_static() { - $.fn.shape.settings.error.method = 'method'; + $.fn.shape.settings.error!.method = 'method'; $.fn.shape.settings.namespace = 'namespace'; $.fn.shape.settings.name = 'name'; $.fn.shape.settings.silent = false; @@ -10,29 +10,30 @@ function test_shape_static() { function test_shape() { const selector = '.ui.shape'; - $(selector).shape('flip up') === $(); - $(selector).shape('flip down') === $(); - $(selector).shape('flip right') === $(); - $(selector).shape('flip left') === $(); - $(selector).shape('flip over') === $(); - $(selector).shape('flip back') === $(); - $(selector).shape('set next side', $()) === $(); - $(selector).shape('is animating') === false; - $(selector).shape('reset') === $(); - $(selector).shape('queue', 'animation') === $(); - $(selector).shape('repaint') === $(); - $(selector).shape('set default side') === $(); - $(selector).shape('set stage size') === $(); - $(selector).shape('refresh') === $(); - $(selector).shape('get transform down') === { transform: 'transform' }; - $(selector).shape('get transform left') === { transform: 'transform' }; - $(selector).shape('get transform right') === { transform: 'transform' }; - $(selector).shape('get transform up') === { transform: 'transform' }; - $(selector).shape('get transform down') === { transform: 'transform' }; - $(selector).shape('destroy') === $(); - $(selector).shape('setting', 'debug', undefined) === false; - $(selector).shape('setting', 'debug') === false; - $(selector).shape('setting', 'debug', true) === $(); + $(selector).shape('flip up'); // $ExpectType JQuery + $(selector).shape('flip down'); // $ExpectType JQuery + $(selector).shape('flip right'); // $ExpectType JQuery + $(selector).shape('flip left'); // $ExpectType JQuery + $(selector).shape('flip over'); // $ExpectType JQuery + $(selector).shape('flip back'); // $ExpectType JQuery + $(selector).shape('set next side', $()); // $ExpectType JQuery + $(selector).shape('is animating'); // $ExpectType boolean + $(selector).shape('reset'); // $ExpectType JQuery + $(selector).shape('queue', 'animation'); // $ExpectType JQuery + $(selector).shape('repaint'); // $ExpectType JQuery + $(selector).shape('set default side'); // $ExpectType JQuery + $(selector).shape('set stage size'); // $ExpectType JQuery + $(selector).shape('refresh'); // $ExpectType JQuery + $(selector).shape('get transform down'); // $ExpectType Translation + $(selector).shape('get transform left'); // $ExpectType Translation + $(selector).shape('get transform right'); // $ExpectType Translation + $(selector).shape('get transform up'); // $ExpectType Translation + $(selector).shape('get transform down'); // $ExpectType Translation + $(selector).shape('destroy'); // $ExpectType JQuery + $(selector).shape('setting', 'debug', undefined); // $ExpectType boolean + $(selector).shape('setting', 'debug'); // $ExpectType boolean + $(selector).shape('setting', 'debug', true); // $ExpectType JQuery + // $ExpectType JQuery $(selector).shape('setting', { namespace: 'namespace', name: 'name', @@ -40,16 +41,17 @@ function test_shape() { debug: true, performance: true, verbose: true - }) === $(); + }); + // $ExpectType JQuery $(selector).shape({ duration: 700, width: 'next', height: 200, beforeChange() { - this === $(); + this; // $ExpectType JQuery }, onChange() { - this === $(); + this; // $ExpectType JQuery }, selector: { sides: 'sides', @@ -65,12 +67,16 @@ function test_shape() { side: 'side', method: 'method' } - }) === $(); - $(selector).shape() === $(); + }); + $(selector).shape(); // $ExpectType JQuery + + $(selector).shape('foo'); // $ExpectError + $(selector).shape({ foo: 'bar' }); // $ExpectError } import shape = require('semantic-ui-shape'); function test_module() { + shape; // $ExpectType Shape $.fn.shape = shape; }