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

This commit is contained in:
Leonard Thieu
2017-06-30 12:26:51 -04:00
parent 40eef89e46
commit e9ae6bd04a
2 changed files with 87 additions and 45 deletions
+45 -12
View File
@@ -56,19 +56,46 @@ declare namespace SemanticUI {
(behavior: 'set active'): JQuery;
(behavior: 'attach events', selector: string | JQuery, event?: string): JQuery;
(behavior: 'destroy'): JQuery;
<K extends keyof ModalSettings>(behavior: 'setting', name: K, value?: undefined): ModalSettings[K];
<K extends keyof ModalSettings>(behavior: 'setting', name: K, value: ModalSettings[K]): JQuery;
(behavior: 'setting', value: ModalSettings.Param): JQuery;
(settings?: ModalSettings.Param): JQuery;
<K extends keyof ModalSettings>(behavior: 'setting', name: K, value?: undefined): ModalSettings._Impl[K];
<K extends keyof ModalSettings>(behavior: 'setting', name: K, value: ModalSettings._Impl[K]): JQuery;
(behavior: 'setting', value: ModalSettings): JQuery;
(settings?: ModalSettings): JQuery;
}
/**
* @see {@link http://semantic-ui.com/modules/modal.html#/settings}
*/
interface ModalSettings extends Pick<ModalSettings._Impl, keyof ModalSettings._Impl> { }
type ModalSettings = ModalSettings.Param;
namespace ModalSettings {
type Param = ModalSettings | object;
type Param = (Pick<_Impl, 'detachable'> |
Pick<_Impl, 'autofocus'> |
Pick<_Impl, 'observeChanges'> |
Pick<_Impl, 'allowMultiple'> |
Pick<_Impl, 'keyboardShortcuts'> |
Pick<_Impl, 'offset'> |
Pick<_Impl, 'context'> |
Pick<_Impl, 'closable'> |
Pick<_Impl, 'dimmerSettings'> |
Pick<_Impl, 'transition'> |
Pick<_Impl, 'duration'> |
Pick<_Impl, 'queue'> |
Pick<_Impl, 'onShow'> |
Pick<_Impl, 'onVisible'> |
Pick<_Impl, 'onHide'> |
Pick<_Impl, 'onHidden'> |
Pick<_Impl, 'onApprove'> |
Pick<_Impl, 'onDeny'> |
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<Pick<_Impl, keyof _Impl>>;
interface _Impl {
// region Modal Settings
@@ -232,10 +259,13 @@ declare namespace SemanticUI {
}
namespace Modal {
interface SelectorSettings extends Pick<SelectorSettings._Impl, keyof SelectorSettings._Impl> { }
type SelectorSettings = SelectorSettings.Param;
namespace SelectorSettings {
type Param = SelectorSettings | object;
type Param = (Pick<_Impl, 'close'> |
Pick<_Impl, 'approve'> |
Pick<_Impl, 'deny'>) &
Partial<Pick<_Impl, keyof _Impl>>;
interface _Impl {
/**
@@ -253,10 +283,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, 'active'> |
Pick<_Impl, 'scrolling'>) &
Partial<Pick<_Impl, keyof _Impl>>;
interface _Impl {
/**
@@ -270,10 +302,11 @@ 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, 'method'>) &
Partial<Pick<_Impl, keyof _Impl>>;
interface _Impl {
/**
@@ -1,5 +1,5 @@
function test_modal_static() {
$.fn.modal.settings.error.method = 'method';
$.fn.modal.settings.error!.method = 'method';
$.fn.modal.settings.namespace = 'namespace';
$.fn.modal.settings.name = 'name';
$.fn.modal.settings.silent = false;
@@ -10,23 +10,24 @@ function test_modal_static() {
function test_modal() {
const selector = '.ui.modal';
$(selector).modal('show') === $();
$(selector).modal('hide') === $();
$(selector).modal('toggle') === $();
$(selector).modal('refresh') === $();
$(selector).modal('show dimmer') === $();
$(selector).modal('hide dimmer') === $();
$(selector).modal('hide others') === $();
$(selector).modal('hide all') === $();
$(selector).modal('cache sizes') === $();
$(selector).modal('can fit') === true;
$(selector).modal('is active') === true;
$(selector).modal('set active') === $();
$(selector).modal('attach events', 'selector', 'blur') === $();
$(selector).modal('destroy') === $();
$(selector).modal('setting', 'debug', undefined) === false;
$(selector).modal('setting', 'debug') === false;
$(selector).modal('setting', 'debug', true) === $();
$(selector).modal('show'); // $ExpectType JQuery<HTMLElement>
$(selector).modal('hide'); // $ExpectType JQuery<HTMLElement>
$(selector).modal('toggle'); // $ExpectType JQuery<HTMLElement>
$(selector).modal('refresh'); // $ExpectType JQuery<HTMLElement>
$(selector).modal('show dimmer'); // $ExpectType JQuery<HTMLElement>
$(selector).modal('hide dimmer'); // $ExpectType JQuery<HTMLElement>
$(selector).modal('hide others'); // $ExpectType JQuery<HTMLElement>
$(selector).modal('hide all'); // $ExpectType JQuery<HTMLElement>
$(selector).modal('cache sizes'); // $ExpectType JQuery<HTMLElement>
$(selector).modal('can fit'); // $ExpectType boolean
$(selector).modal('is active'); // $ExpectType boolean
$(selector).modal('set active'); // $ExpectType JQuery<HTMLElement>
$(selector).modal('attach events', 'selector', 'blur'); // $ExpectType JQuery<HTMLElement>
$(selector).modal('destroy'); // $ExpectType JQuery<HTMLElement>
$(selector).modal('setting', 'debug', undefined); // $ExpectType boolean
$(selector).modal('setting', 'debug'); // $ExpectType boolean
$(selector).modal('setting', 'debug', true); // $ExpectType JQuery<HTMLElement>
// $ExpectType JQuery<HTMLElement>
$(selector).modal('setting', {
namespace: 'namespace',
name: 'name',
@@ -34,7 +35,8 @@ function test_modal() {
debug: true,
performance: true,
verbose: true
}) === $();
});
// $ExpectType JQuery<HTMLElement>
$(selector).modal({
detachable: true,
autofocus: false,
@@ -57,13 +59,13 @@ function test_modal() {
},
transition: 'fade',
onShow() {
this === $();
this; // $ExpectType JQuery<HTMLElement>
},
onHide() {
this === $();
this; // $ExpectType JQuery<HTMLElement>
},
onChange() {
this === $();
this; // $ExpectType JQuery<HTMLElement>
},
selector: {
dimmable: '.dimmable',
@@ -93,27 +95,30 @@ function test_modal() {
duration: 400,
queue: true,
onShow() {
this === $();
this; // $ExpectType JQuery<HTMLElement>
},
onVisible() {
this === $();
this; // $ExpectType JQuery<HTMLElement>
},
onHide($element) {
this === $();
$element === $();
this; // $ExpectType JQuery<HTMLElement>
$element; // $ExpectType JQuery<HTMLElement>
return false;
},
onHidden() {
this === $();
this; // $ExpectType JQuery<HTMLElement>
},
onApprove($element) {
this === $();
$element === $();
this; // $ExpectType JQuery<HTMLElement>
$element; // $ExpectType JQuery<HTMLElement>
return false;
},
onDeny($element) {
this === $();
$element === $();
this; // $ExpectType JQuery<HTMLElement>
$element; // $ExpectType JQuery<HTMLElement>
return false;
},
selector: {
@@ -128,12 +133,16 @@ function test_modal() {
error: {
method: 'method'
}
}) === $();
$(selector).modal() === $();
});
$(selector).modal(); // $ExpectType JQuery<HTMLElement>
$(selector).modal('foo'); // $ExpectError
$(selector).modal({ foo: 'bar' }); // $ExpectError
}
import modal = require('semantic-ui-modal');
function test_module() {
modal; // $ExpectType Modal
$.fn.modal = modal;
}