[semantic-ui-nag] Different weak-type workaround.

This commit is contained in:
Leonard Thieu
2017-06-30 12:31:11 -04:00
parent e9ae6bd04a
commit 0657aa2c61
2 changed files with 60 additions and 26 deletions

View File

@@ -13,19 +13,42 @@ declare namespace SemanticUI {
*/
(behavior: 'clear'): JQuery;
(behavior: 'destroy'): JQuery;
<K extends keyof NagSettings>(behavior: 'setting', name: K, value?: undefined): NagSettings[K];
<K extends keyof NagSettings>(behavior: 'setting', name: K, value: NagSettings[K]): JQuery;
(behavior: 'setting', value: NagSettings.Param): JQuery;
(settings?: NagSettings.Param): JQuery;
<K extends keyof NagSettings>(behavior: 'setting', name: K, value?: undefined): NagSettings._Impl[K];
<K extends keyof NagSettings>(behavior: 'setting', name: K, value: NagSettings._Impl[K]): JQuery;
(behavior: 'setting', value: NagSettings): JQuery;
(settings?: NagSettings): JQuery;
}
/**
* @see {@link http://semantic-ui.com/modules/nag.html}
*/
interface NagSettings extends Pick<NagSettings._Impl, keyof NagSettings._Impl> { }
type NagSettings = NagSettings.Param;
namespace NagSettings {
type Param = NagSettings | object;
type Param = (Pick<_Impl, 'persist'> |
Pick<_Impl, 'displayTime'> |
Pick<_Impl, 'animation'> |
Pick<_Impl, 'context'> |
Pick<_Impl, 'detachable'> |
Pick<_Impl, 'expires'> |
Pick<_Impl, 'domain'> |
Pick<_Impl, 'path'> |
Pick<_Impl, 'storageMethod'> |
Pick<_Impl, 'key'> |
Pick<_Impl, 'value'> |
Pick<_Impl, 'speed'> |
Pick<_Impl, 'easing'> |
Pick<_Impl, 'onHide'> |
Pick<_Impl, 'className'> |
Pick<_Impl, 'selector'> |
Pick<_Impl, 'error'> |
Pick<_Impl, 'namespace'> |
Pick<_Impl, 'name'> |
Pick<_Impl, 'silent'> |
Pick<_Impl, 'debug'> |
Pick<_Impl, 'performance'> |
Pick<_Impl, 'verbose'>) &
Partial<Pick<_Impl, keyof _Impl>>;
interface _Impl {
// region Behavior
@@ -152,10 +175,12 @@ declare namespace SemanticUI {
}
namespace Nag {
interface AnimationSettings extends Pick<AnimationSettings._Impl, keyof AnimationSettings._Impl> { }
type AnimationSettings = AnimationSettings.Param;
namespace AnimationSettings {
type Param = AnimationSettings | object;
type Param = (Pick<_Impl, 'show'> |
Pick<_Impl, 'hide'>) &
Partial<Pick<_Impl, keyof _Impl>>;
interface _Impl {
/**
@@ -169,10 +194,12 @@ declare namespace SemanticUI {
}
}
interface ClassNameSettings extends Pick<ClassNameSettings._Impl, keyof ClassNameSettings._Impl> { }
type ClassNameSettings = ClassNameSettings.Param;
namespace ClassNameSettings {
type Param = ClassNameSettings | object;
type Param = (Pick<_Impl, 'bottom'> |
Pick<_Impl, 'fixed'>) &
Partial<Pick<_Impl, keyof _Impl>>;
interface _Impl {
/**
@@ -186,10 +213,11 @@ declare namespace SemanticUI {
}
}
interface SelectorSettings extends Pick<SelectorSettings._Impl, keyof SelectorSettings._Impl> { }
type SelectorSettings = SelectorSettings.Param;
namespace SelectorSettings {
type Param = SelectorSettings | object;
type Param = (Pick<_Impl, 'close'>) &
Partial<Pick<_Impl, keyof _Impl>>;
interface _Impl {
/**
@@ -199,10 +227,13 @@ declare namespace SemanticUI {
}
}
interface ErrorSettings extends Pick<ErrorSettings._Impl, keyof ErrorSettings._Impl> { }
type ErrorSettings = ErrorSettings.Param;
namespace ErrorSettings {
type Param = ErrorSettings | object;
type Param = (Pick<_Impl, 'noCookieStorage'> |
Pick<_Impl, 'noStorage'> |
Pick<_Impl, 'method'>) &
Partial<Pick<_Impl, keyof _Impl>>;
interface _Impl {
/**

View File

@@ -1,5 +1,5 @@
function test_nag_static() {
$.fn.nag.settings.error.method = 'method';
$.fn.nag.settings.error!.method = 'method';
$.fn.nag.settings.namespace = 'namespace';
$.fn.nag.settings.name = 'name';
$.fn.nag.settings.silent = false;
@@ -10,13 +10,14 @@ function test_nag_static() {
function test_nag() {
const selector = '.ui.nag';
$(selector).nag('show') === $();
$(selector).nag('hide') === $();
$(selector).nag('clear') === $();
$(selector).nag('destroy') === $();
$(selector).nag('setting', 'debug', undefined) === false;
$(selector).nag('setting', 'debug') === false;
$(selector).nag('setting', 'debug', true) === $();
$(selector).nag('show'); // $ExpectType JQuery<HTMLElement>
$(selector).nag('hide'); // $ExpectType JQuery<HTMLElement>
$(selector).nag('clear'); // $ExpectType JQuery<HTMLElement>
$(selector).nag('destroy'); // $ExpectType JQuery<HTMLElement>
$(selector).nag('setting', 'debug', undefined); // $ExpectType boolean
$(selector).nag('setting', 'debug'); // $ExpectType boolean
$(selector).nag('setting', 'debug', true); // $ExpectType JQuery<HTMLElement>
// $ExpectType JQuery<HTMLElement>
$(selector).nag('setting', {
namespace: 'namespace',
name: 'name',
@@ -24,7 +25,8 @@ function test_nag() {
debug: true,
performance: true,
verbose: true
}) === $();
});
// $ExpectType JQuery<HTMLElement>
$(selector).nag({
persist: true,
displayTime: 0,
@@ -43,7 +45,7 @@ function test_nag() {
speed: 500,
easing: 'easeOutQuad',
onHide() {
this === $();
this; // $ExpectType JQuery<HTMLElement>
},
className: {
bottom: 'bottom',
@@ -57,12 +59,13 @@ function test_nag() {
noStorage: 'noStorage',
method: 'method'
}
}) === $();
$(selector).nag() === $();
});
$(selector).nag(); // $ExpectType JQuery<HTMLElement>
}
import nag = require('semantic-ui-nag');
function test_module() {
nag; // $ExpectType Nag
$.fn.nag = nag;
}