From a718e41a609ca3a043dc62040cada98870b1e0a2 Mon Sep 17 00:00:00 2001 From: Leonard Thieu Date: Fri, 30 Jun 2017 14:05:05 -0400 Subject: [PATCH] [semantic-ui-visibility] Different weak-type workaround. --- types/semantic-ui-visibility/global.d.ts | 63 ++++++++-- .../semantic-ui-visibility-tests.ts | 119 ++++++------------ 2 files changed, 94 insertions(+), 88 deletions(-) diff --git a/types/semantic-ui-visibility/global.d.ts b/types/semantic-ui-visibility/global.d.ts index fa735676c5..1f582bf257 100644 --- a/types/semantic-ui-visibility/global.d.ts +++ b/types/semantic-ui-visibility/global.d.ts @@ -39,19 +39,60 @@ declare namespace SemanticUI { */ (behavior: 'get screen size'): Visibility.ScreenSize; (behavior: 'destroy'): JQuery; - (behavior: 'setting', name: K, value?: undefined): VisibilitySettings[K]; - (behavior: 'setting', name: K, value: VisibilitySettings[K]): JQuery; - (behavior: 'setting', value: VisibilitySettings.Param): JQuery; - (settings?: VisibilitySettings.Param): JQuery; + (behavior: 'setting', name: K, value?: undefined): VisibilitySettings._Impl[K]; + (behavior: 'setting', name: K, value: VisibilitySettings._Impl[K]): JQuery; + (behavior: 'setting', value: VisibilitySettings): JQuery; + (settings?: VisibilitySettings): JQuery; } /** * @see {@link http://semantic-ui.com/behaviors/visibility.html#/settings} */ - interface VisibilitySettings extends Pick { } + type VisibilitySettings = VisibilitySettings.Param; namespace VisibilitySettings { - type Param = VisibilitySettings | object; + type Param = (Pick<_Impl, 'once'> | + Pick<_Impl, 'continuous'> | + Pick<_Impl, 'type'> | + Pick<_Impl, 'initialCheck'> | + Pick<_Impl, 'context'> | + Pick<_Impl, 'refreshOnLoad'> | + Pick<_Impl, 'refreshOnResize'> | + Pick<_Impl, 'checkOnRefresh'> | + Pick<_Impl, 'zIndex'> | + Pick<_Impl, 'offset'> | + Pick<_Impl, 'includeMargin'> | + Pick<_Impl, 'throttle'> | + Pick<_Impl, 'observeChanges'> | + Pick<_Impl, 'transition'> | + Pick<_Impl, 'duration'> | + Pick<_Impl, 'onTopVisible'> | + Pick<_Impl, 'onTopPassed'> | + Pick<_Impl, 'onBottomVisible'> | + Pick<_Impl, 'onPassing'> | + Pick<_Impl, 'onBottomPassed'> | + Pick<_Impl, 'onTopVisibleReverse'> | + Pick<_Impl, 'onTopPassedReverse'> | + Pick<_Impl, 'onBottomVisibleReverse'> | + Pick<_Impl, 'onPassingReverse'> | + Pick<_Impl, 'onBottomPassedReverse'> | + Pick<_Impl, 'onOnScreen'> | + Pick<_Impl, 'onOffScreen'> | + Pick<_Impl, 'onLoad'> | + Pick<_Impl, 'onAllLoaded'> | + Pick<_Impl, 'onFixed'> | + Pick<_Impl, 'onUnfixed'> | + Pick<_Impl, 'onUpdate'> | + Pick<_Impl, 'onRefresh'> | + 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 Functionality @@ -337,10 +378,11 @@ declare namespace SemanticUI { height: number; } - interface ClassNameSettings extends Pick { } + type ClassNameSettings = ClassNameSettings.Param; namespace ClassNameSettings { - type Param = ClassNameSettings | object; + type Param = (Pick<_Impl, 'fixed'>) & + Partial>; interface _Impl { /** @@ -350,10 +392,11 @@ declare namespace SemanticUI { } } - interface ErrorSettings extends Pick { } + type ErrorSettings = ErrorSettings.Param; namespace ErrorSettings { - type Param = ErrorSettings | object; + type Param = (Pick<_Impl, 'method'>) & + Partial>; interface _Impl { /** diff --git a/types/semantic-ui-visibility/semantic-ui-visibility-tests.ts b/types/semantic-ui-visibility/semantic-ui-visibility-tests.ts index 960eeb5215..44d8bb0361 100644 --- a/types/semantic-ui-visibility/semantic-ui-visibility-tests.ts +++ b/types/semantic-ui-visibility/semantic-ui-visibility-tests.ts @@ -1,5 +1,5 @@ function test_visibility_static() { - $.fn.visibility.settings.error.method = 'method'; + $.fn.visibility.settings.error!.method = 'method'; $.fn.visibility.settings.namespace = 'namespace'; $.fn.visibility.settings.name = 'name'; $.fn.visibility.settings.silent = false; @@ -10,42 +10,19 @@ function test_visibility_static() { function test_visibility() { const selector = '.ui.visibility'; - $(selector).visibility('disable callbacks') === $(); - $(selector).visibility('enable callbacks') === $(); - $(selector).visibility('is on screen') === false; - $(selector).visibility('is off screen') === true; - $(selector).visibility('get pixels passed') === 20; - $(selector).visibility('get element calculations') === { - fits: false, - offset: { - top: 955.96875, - left: 292 - }, - width: 466, - height: 1665.890625, - top: 955.96875, - bottom: 2621.859375, - topPassed: true, - bottomPassed: false, - topVisible: true, - bottomVisible: false, - pixelsPassed: 742.03125, - percentagePassed: 0.44542615155182, - onScreen: true, - passing: true, - offScreen: false - }; - $(selector).visibility('get screen calculations') === { - bottom: 2658, - top: 1698 - }; - $(selector).visibility('get screen size') === { - height: 960 - }; - $(selector).visibility('destroy') === $(); - $(selector).visibility('setting', 'debug', undefined) === false; - $(selector).visibility('setting', 'debug') === false; - $(selector).visibility('setting', 'debug', true) === $(); + $(selector).visibility('disable callbacks'); // $ExpectType JQuery + $(selector).visibility('enable callbacks'); // $ExpectType JQuery + $(selector).visibility('is on screen'); // $ExpectType boolean + $(selector).visibility('is off screen'); // $ExpectType boolean + $(selector).visibility('get pixels passed'); // $ExpectType number + $(selector).visibility('get element calculations'); // $ExpectType ElementCalculations + $(selector).visibility('get screen calculations'); // $ExpectType ScreenCalculations + $(selector).visibility('get screen size'); // $ExpectType ScreenSize + $(selector).visibility('destroy'); // $ExpectType JQuery + $(selector).visibility('setting', 'debug', undefined); // $ExpectType boolean + $(selector).visibility('setting', 'debug'); // $ExpectType boolean + $(selector).visibility('setting', 'debug', true); // $ExpectType JQuery + // $ExpectType JQuery $(selector).visibility('setting', { namespace: 'namespace', name: 'name', @@ -53,7 +30,8 @@ function test_visibility() { debug: true, performance: true, verbose: true - }) === $(); + }); + // $ExpectType JQuery $(selector).visibility({ once: false, continuous: true, @@ -71,78 +49,59 @@ function test_visibility() { transition: 'fade', duration: 5, onTopVisible() { - this === $(); + this; // $ExpectType JQuery }, onTopPassed() { - this === $(); + this; // $ExpectType JQuery }, onBottomVisible() { - this === $(); + this; // $ExpectType JQuery }, onPassing() { - this === $(); + this; // $ExpectType JQuery }, onBottomPassed() { - this === $(); + this; // $ExpectType JQuery }, onTopVisibleReverse() { - this === $(); + this; // $ExpectType JQuery }, onTopPassedReverse() { - this === $(); + this; // $ExpectType JQuery }, onBottomVisibleReverse() { - this === $(); + this; // $ExpectType JQuery }, onPassingReverse() { - this === $(); + this; // $ExpectType JQuery }, onBottomPassedReverse() { - this === $(); + this; // $ExpectType JQuery }, onOnScreen() { - this === $(); + this; // $ExpectType JQuery }, onOffScreen() { - this === $(); + this; // $ExpectType JQuery }, onLoad() { - this === $(); + this; // $ExpectType JQuery }, onAllLoaded() { - this === $(); + this; // $ExpectType JQuery }, onFixed() { - this === $(); + this; // $ExpectType JQuery }, onUnfixed() { - this === $(); + this; // $ExpectType JQuery }, onUpdate(calculations) { - this === $(); - calculations === { - fits: false, - offset: { - top: 955.96875, - left: 292 - }, - width: 466, - height: 1665.890625, - top: 955.96875, - bottom: 2621.859375, - topPassed: true, - bottomPassed: false, - topVisible: true, - bottomVisible: false, - pixelsPassed: 742.03125, - percentagePassed: 0.44542615155182, - onScreen: true, - passing: true, - offScreen: false - }; + this; // $ExpectType JQuery + calculations; // $ExpectType ElementCalculations }, onRefresh() { - this === $(); + this; // $ExpectType JQuery }, className: { fixed: 'fixed', @@ -150,12 +109,16 @@ function test_visibility() { error: { method: 'method' } - }) === $(); - $(selector).visibility() === $(); + }); + $(selector).visibility(); // $ExpectType JQuery + + $(selector).visibility('foo'); // $ExpectError + $(selector).visibility({ foo: 'bar' }); // $ExpectError } import visibility = require('semantic-ui-visibility'); function test_module() { + visibility; // $ExpectType Visibility $.fn.visibility = visibility; }