diff --git a/types/mailcheck/index.d.ts b/types/mailcheck/index.d.ts index 5c42ec02c6..bf181ee80c 100644 --- a/types/mailcheck/index.d.ts +++ b/types/mailcheck/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/mailcheck/mailcheck // Definitions by: Paulo Cesar // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 3.8 /// @@ -46,23 +46,31 @@ declare namespace MailcheckModule { full: string; } - export interface IOptions { + export interface IAsynchronousOptions { email: string; domains?: string[]; secondLevelDomains?: string[]; topLevelDomains?: string[]; distanceFunction?: IDistanceFunction; - suggested?: ISuggested | IJQuerySuggested; + suggested: ISuggested | IJQuerySuggested; empty?: IEmpty | IJQueryEmpty; } + export interface ISynchronousOptions { + email: string; + domains?: string[]; + secondLevelDomains?: string[]; + topLevelDomains?: string[]; + distanceFunction?: IDistanceFunction; + } export interface Static { defaultDomains: string[]; defaultSecondLevelDomains: string[]; defaultTopLevelDomains: string[]; domainThreshold: number; topLevelThreshold: number; - run(opts: IOptions):void; + run(opts: IAsynchronousOptions):void; + run(opts: ISynchronousOptions):ISuggestion | undefined; suggest: ISuggestFunction; encodeEmail(email: string): string; splitEmail(email: string): ISplitEmail; @@ -73,7 +81,8 @@ declare namespace MailcheckModule { } interface JQuery { - mailcheck(opts: MailcheckModule.IOptions): void; + mailcheck(opts: MailcheckModule.IAsynchronousOptions):void; + mailcheck(opts: MailcheckModule.ISynchronousOptions):MailcheckModule.ISuggestion | void; } declare module 'mailcheck' { diff --git a/types/mailcheck/mailcheck-tests.ts b/types/mailcheck/mailcheck-tests.ts index 971ecf8218..67081002bb 100644 --- a/types/mailcheck/mailcheck-tests.ts +++ b/types/mailcheck/mailcheck-tests.ts @@ -18,6 +18,8 @@ $('#email').on('blur', function() { distanceFunction: superStringDistance, // optional suggested: function(element: JQuery, suggestion: MailcheckModule.ISuggestion) { // callback code + element; // $ExpectType JQuery + suggestion; // $ExpectType ISuggestion }, empty: function(element: JQuery) { // callback code @@ -33,6 +35,7 @@ Mailcheck.run({ distanceFunction: superStringDistance, // optional suggested: function(suggestion: MailcheckModule.ISuggestion) { // callback code + suggestion; // $ExpectType ISuggestion }, empty: function() { // callback code @@ -47,9 +50,18 @@ MC.run({ distanceFunction: superStringDistance, // optional suggested: function(suggested: MailcheckModule.ISuggestion) { // callback code - suggested.address === '' && suggested.full === '' && suggested.domain === ''; + suggested; // $ExpectType ISuggestion }, empty: function() { // callback code } -}); \ No newline at end of file +}); + +const result3 = MC.run({ + email: 'nonoptional@example.com', + domains: domains, // optional + secondLevelDomains: secondLevelDomains, // optional + topLevelDomains: topLevelDomains, // optional + distanceFunction: superStringDistance, // optional +}); +result3; // $ExpectType ISuggestion | undefined \ No newline at end of file