diff --git a/types/semantic-ui-checkbox/global.d.ts b/types/semantic-ui-checkbox/global.d.ts index fd3159b5b6..45733f20f6 100644 --- a/types/semantic-ui-checkbox/global.d.ts +++ b/types/semantic-ui-checkbox/global.d.ts @@ -97,17 +97,41 @@ declare namespace SemanticUI { (behavior: 'destroy'): JQuery; (behavior: 'setting', name: K, value?: undefined): CheckboxSettings[K]; (behavior: 'setting', name: K, value: CheckboxSettings[K]): JQuery; - (behavior: 'setting', value: CheckboxSettings.Param): JQuery; - (settings?: CheckboxSettings.Param): JQuery; + (behavior: 'setting', value: CheckboxSettings): JQuery; + (settings?: CheckboxSettings): JQuery; } /** * @see {@link http://semantic-ui.com/modules/checkbox.html#/settings} */ - interface CheckboxSettings extends Pick { } + type CheckboxSettings = CheckboxSettings.Param; namespace CheckboxSettings { - type Param = CheckboxSettings | object; + type Param = (Pick<_Impl, 'uncheckable'> | + Pick<_Impl, 'fireOnInit'> | + Pick<_Impl, 'onChange'> | + Pick<_Impl, 'onChecked'> | + Pick<_Impl, 'onIndeterminate'> | + Pick<_Impl, 'onDeterminate'> | + Pick<_Impl, 'onUnchecked'> | + Pick<_Impl, 'beforeChecked'> | + Pick<_Impl, 'beforeIndeterminate'> | + Pick<_Impl, 'beforeDeterminate'> | + Pick<_Impl, 'beforeUnchecked'> | + Pick<_Impl, 'onEnable'> | + Pick<_Impl, 'onDisable'> | + Pick<_Impl, 'onEnabled'> | + Pick<_Impl, 'onDisabled'> | + 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 Behavior @@ -152,19 +176,19 @@ declare namespace SemanticUI { /** * Callback before a checkbox is checked. Can cancel change by returning false */ - beforeChecked(this: HTMLElement): boolean; + beforeChecked(this: HTMLElement): void | false; /** * Callback before a checkbox is set to undeterminate. Can cancel change by returning false */ - beforeIndeterminate(this: HTMLElement): boolean; + beforeIndeterminate(this: HTMLElement): void | false; /** * Callback before a checkbox is set to determinate. Can cancel change by returning false */ - beforeDeterminate(this: HTMLElement): boolean; + beforeDeterminate(this: HTMLElement): void | false; /** * Callback before a checkbox is unchecked. Can cancel change by returning false */ - beforeUnchecked(this: HTMLElement): boolean; + beforeUnchecked(this: HTMLElement): void | false; /** * Callback after a checkbox is enabled. */ @@ -248,10 +272,12 @@ declare namespace SemanticUI { } namespace Checkbox { - interface SelectorSettings extends Pick { } + type SelectorSettings = SelectorSettings.Param; namespace SelectorSettings { - type Param = SelectorSettings | object; + type Param = (Pick<_Impl, 'input'> | + Pick<_Impl, 'label'>) & + Partial>; interface _Impl { /** @@ -265,10 +291,14 @@ declare namespace SemanticUI { } } - interface ClassNameSettings extends Pick { } + type ClassNameSettings = ClassNameSettings.Param; namespace ClassNameSettings { - type Param = ClassNameSettings | object; + type Param = (Pick<_Impl, 'checked'> | + Pick<_Impl, 'disabled'> | + Pick<_Impl, 'radio'> | + Pick<_Impl, 'readOnly'>) & + Partial>; interface _Impl { /** @@ -290,10 +320,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-checkbox/semantic-ui-checkbox-tests.ts b/types/semantic-ui-checkbox/semantic-ui-checkbox-tests.ts index 30ff41ebd3..fbb15ca33e 100644 --- a/types/semantic-ui-checkbox/semantic-ui-checkbox-tests.ts +++ b/types/semantic-ui-checkbox/semantic-ui-checkbox-tests.ts @@ -1,5 +1,5 @@ function test_checkbox_static() { - $.fn.checkbox.settings.error.method = 'method'; + $.fn.checkbox.settings.error!.method = 'method'; $.fn.checkbox.settings.namespace = 'namespace'; $.fn.checkbox.settings.name = 'name'; $.fn.checkbox.settings.silent = false; @@ -10,19 +10,19 @@ function test_checkbox_static() { function test_checkbox() { const selector = '.ui.checkbox'; - $(selector).checkbox('toggle') === $(); - $(selector).checkbox('check') === $(); - $(selector).checkbox('uncheck') === $(); - $(selector).checkbox('indeterminate') === $(); - $(selector).checkbox('determinate') === $(); - $(selector).checkbox('enable') === $(); - $(selector).checkbox('set checked') === $(); - $(selector).checkbox('set unchecked') === $(); - $(selector).checkbox('set indeterminate') === $(); - $(selector).checkbox('set determinate') === $(); - $(selector).checkbox('set enabled') === $(); - $(selector).checkbox('set disabled') === $(); - $(selector).checkbox('attach events', $(), 'click') === $(); + $(selector).checkbox('toggle'); // $ExpectType JQuery + $(selector).checkbox('check'); // $ExpectType JQuery + $(selector).checkbox('uncheck'); // $ExpectType JQuery + $(selector).checkbox('indeterminate'); // $ExpectType JQuery + $(selector).checkbox('determinate'); // $ExpectType JQuery + $(selector).checkbox('enable'); // $ExpectType JQuery + $(selector).checkbox('set checked'); // $ExpectType JQuery + $(selector).checkbox('set unchecked'); // $ExpectType JQuery + $(selector).checkbox('set indeterminate'); // $ExpectType JQuery + $(selector).checkbox('set determinate'); // $ExpectType JQuery + $(selector).checkbox('set enabled'); // $ExpectType JQuery + $(selector).checkbox('set disabled'); // $ExpectType JQuery + $(selector).checkbox('attach events', $(), 'click'); // $ExpectType JQuery $(selector).checkbox('is radio') === true; $(selector).checkbox('is checked') === true; $(selector).checkbox('is unchecked') === true; @@ -34,7 +34,8 @@ function test_checkbox() { $(selector).checkbox('can uncheck') === true; $(selector).checkbox('setting', 'debug', undefined) === false; $(selector).checkbox('setting', 'debug') === false; - $(selector).checkbox('setting', 'debug', true) === $(); + $(selector).checkbox('setting', 'debug', true); // $ExpectType JQuery + // $ExpectType JQuery $(selector).checkbox('setting', { namespace: 'namespace', name: 'name', @@ -42,48 +43,57 @@ function test_checkbox() { debug: true, performance: true, verbose: true - }) === $(); + }); + // $ExpectType JQuery $(selector).checkbox({ uncheckable: false, fireOnInit: true, onChange() { - this === new HTMLElement(); + this; // $ExpectType HTMLElement }, onChecked() { - this === new HTMLElement(); + this; // $ExpectType HTMLElement }, onIndeterminate() { - this === new HTMLElement(); + this; // $ExpectType HTMLElement }, onDeterminate() { - this === new HTMLElement(); + this; // $ExpectType HTMLElement }, onUnchecked() { - this === new HTMLElement(); + this; // $ExpectType HTMLElement }, beforeChecked() { - this === new HTMLElement(); + this; // $ExpectType HTMLElement + + return false; }, beforeIndeterminate() { - this === new HTMLElement(); + this; // $ExpectType HTMLElement + + return false; }, beforeDeterminate() { - this === new HTMLElement(); + this; // $ExpectType HTMLElement + + return false; }, beforeUnchecked() { - this === new HTMLElement(); + this; // $ExpectType HTMLElement + + return false; }, onEnable() { - this === new HTMLElement(); + this; // $ExpectType HTMLElement }, onDisable() { - this === new HTMLElement(); + this; // $ExpectType HTMLElement }, onEnabled() { - this === new HTMLElement(); + this; // $ExpectType HTMLElement }, onDisabled() { - this === new HTMLElement(); + this; // $ExpectType HTMLElement }, selector: { input: 'input', @@ -98,12 +108,16 @@ function test_checkbox() { error: { method: 'method' } - }) === $(); - $(selector).checkbox() === $(); + }); + $(selector).checkbox(); // $ExpectType JQuery + + $(selector).checkbox('foo'); // $ExpectError + $(selector).checkbox({ foo: 'bar' }); // $ExpectError } import checkbox = require('semantic-ui-checkbox'); function test_module() { + checkbox; // $ExpectType Checkbox $.fn.checkbox = checkbox; }