From 12469ce0d02889a15e91c5f519fbe9a47199fa52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Ga=C5=82uszka?= Date: Mon, 10 Jul 2017 11:49:10 +0200 Subject: [PATCH 01/14] [stripe] fix definitions files and tests --- types/stripe-v2/index.d.ts | 173 +++++++++++++++++++ types/stripe-v2/stripe-v2-tests.ts | 32 ++++ types/{stripe => stripe-v2}/tsconfig.json | 2 +- types/{stripe => stripe-v2}/tslint.json | 0 types/{stripe => stripe-v3}/index.d.ts | 18 +- types/stripe-v3/stripe-v3-tests.ts | 113 ++++++++++++ types/{stripe/v2 => stripe-v3}/tsconfig.json | 9 +- types/{stripe/v2 => stripe-v3}/tslint.json | 0 types/stripe/stripe-tests.ts | 39 ----- types/stripe/v2/index.d.ts | 170 ------------------ types/stripe/v2/stripe-tests.ts | 25 --- 11 files changed, 336 insertions(+), 245 deletions(-) create mode 100644 types/stripe-v2/index.d.ts create mode 100644 types/stripe-v2/stripe-v2-tests.ts rename types/{stripe => stripe-v2}/tsconfig.json (93%) rename types/{stripe => stripe-v2}/tslint.json (100%) rename types/{stripe => stripe-v3}/index.d.ts (93%) create mode 100644 types/stripe-v3/stripe-v3-tests.ts rename types/{stripe/v2 => stripe-v3}/tsconfig.json (73%) rename types/{stripe/v2 => stripe-v3}/tslint.json (100%) delete mode 100644 types/stripe/stripe-tests.ts delete mode 100644 types/stripe/v2/index.d.ts delete mode 100644 types/stripe/v2/stripe-tests.ts diff --git a/types/stripe-v2/index.d.ts b/types/stripe-v2/index.d.ts new file mode 100644 index 0000000000..563fb89780 --- /dev/null +++ b/types/stripe-v2/index.d.ts @@ -0,0 +1,173 @@ +// Type definitions for stripe-v2 2.x +// Project: https://stripe.com/ +// Definitions by: Andy Hawkins +// Eric J. Smith +// Amrit Kahlon +// Adam Cmiel +// Justin Leider +// Kamil Gałuszka +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare var Stripe: stripe.StripeStatic; + +declare namespace stripe { + interface StripeStatic { + applePay: StripeApplePay; + setPublishableKey(key: string): void; + validateCardNumber(cardNumber: string): boolean; + validateExpiry(month: string, year: string): boolean; + validateCVC(cardCVC: string): boolean; + cardType(cardNumber: string): StripeCardDataBrand; + getToken(token: string, responseHandler: (status: number, response: StripeCardTokenResponse) => void): void; + card: StripeCard; + createToken(data: StripeCardTokenData, responseHandler: (status: number, response: StripeCardTokenResponse) => void): void; + bankAccount: StripeBankAccount; + } + + interface StripeCardTokenData { + number: string; + exp_month?: number; + exp_year?: number; + exp?: string; + cvc?: string; + name?: string; + address_line1?: string; + address_line2?: string; + address_city?: string; + address_state?: string; + address_zip?: string; + address_country?: string; + } + + interface StripeTokenResponse { + id: string; + client_ip: string; + created: number; + livemode: boolean; + object: string; + type: string; + used: boolean; + error?: StripeError; + } + + interface StripeCardTokenResponse extends StripeTokenResponse { + card: StripeCard; + } + + interface StripeError { + type: string; + code: string; + message: string; + param?: string; + } + + type StripeCardDataBrand = 'Visa' | 'American Express' | 'MasterCard' | 'Discover' | 'JCB' | 'Diners Club' | 'Unknown'; + + type StripeCardDataFunding = 'credit' | 'debit' | 'prepaid' | 'unknown'; + + interface StripeCard { + object: string; + last4: string; + exp_month: number; + exp_year: number; + country?: string; + name?: string; + address_line1?: string; + address_line2?: string; + address_city?: string; + address_state?: string; + address_zip?: string; + address_country?: string; + brand?: StripeCardDataBrand; + funding?: StripeCardDataFunding; + createToken(data: StripeCardTokenData, responseHandler: (status: number, response: StripeCardTokenResponse) => void): void; + validateCardNumber(cardNumber: string): boolean; + validateExpiry(month: string, year: string): boolean; + validateCVC(cardCVC: string): boolean; + } + + interface StripeBankAccount { + createToken(params: StripeBankTokenParams, stripeResponseHandler: (status: number, response: StripeBankTokenResponse) => void): void; + validateRoutingNumber(routingNumber: number | string, countryCode: string): boolean; + validateAccountNumber(accountNumber: number | string, countryCode: string): boolean; + } + + interface StripeBankTokenParams { + country: string; + currency: string; + account_number: number | string; + routing_number?: number | string; + account_holder_name: string; + account_holder_type: string; + } + + interface StripeBankTokenResponse extends StripeTokenResponse { + bank_account: { + country: string; + bank_name: string; + last4: number; + validated: boolean; + object: string; + }; + } + + interface StripeApplePay { + checkAvailability(resopnseHandler: (result: boolean) => void): void; + buildSession(data: StripeApplePayPaymentRequest, + onSuccessHandler: (result: StripeApplePaySessionResult, completion: ((value: any) => void)) => void, + onErrorHanlder: (error: { message: string }) => void): any; + } + + type StripeApplePayBillingContactField = 'postalAddress' | 'name'; + type StripeApplePayShippingContactField = StripeApplePayBillingContactField | 'phone' | 'email'; + type StripeApplePayShipping = 'shipping' | 'delivery' | 'storePickup' | 'servicePickup'; + + interface StripeApplePayPaymentRequest { + billingContact: StripeApplePayPaymentContact; + countryCode: string; + currencyCode: string; + total: StripeApplePayLineItem; + lineItems?: StripeApplePayLineItem[]; + requiredBillingContactFields?: StripeApplePayBillingContactField[]; + requiredShippingContactFields?: StripeApplePayShippingContactField[]; + shippingContact?: StripeApplePayPaymentContact; + shippingMethods?: StripeApplePayShippingMethod[]; + shippingType?: StripeApplePayShipping[]; + } + + // https://developer.apple.com/reference/applepayjs/1916082-applepay_js_data_types + interface StripeApplePayLineItem { + type: 'pending' | 'final'; + label: string; + amount: number; + } + + interface StripeApplePaySessionResult { + token: StripeCardTokenResponse; + shippingContact?: StripeApplePayPaymentContact; + shippingMethod?: StripeApplePayShippingMethod; + } + + interface StripeApplePayShippingMethod { + label: string; + detail: string; + amount: number; + identifier: string; + } + + interface StripeApplePayPaymentContact { + emailAddress: string; + phoneNumber: string; + givenName: string; + familyName: string; + addressLines: string[]; + locality: string; + administrativeArea: string; + postalCode: string; + countryCode: string; + } +} + +// The Stripe client side APIs are not made available to package managers for direct installation. +// As explained compliance reasons. Source: https://github.com/stripe/stripe-node/blob/master/README.md#these-are-serverside-bindings-only +// A release date versioning schema is used to version these APIs. diff --git a/types/stripe-v2/stripe-v2-tests.ts b/types/stripe-v2/stripe-v2-tests.ts new file mode 100644 index 0000000000..936d311f53 --- /dev/null +++ b/types/stripe-v2/stripe-v2-tests.ts @@ -0,0 +1,32 @@ +declare function describe(desc: string, fn: () => void): void; +declare function it(desc: string, fn: () => void): void; + +describe("Stripe", () => { + it("should excercise Stripe API", () => { + function success(card: stripe.StripeCard) { + console.log(card.brand && card.brand.toString()); + } + + const cardNumber = '4242424242424242'; + + const isValid = Stripe.validateCardNumber(cardNumber); + if (isValid) { + const tokenData: stripe.StripeCardTokenData = { + number: cardNumber, + exp_month: 1, + exp_year: 2100, + cvc: '111' + }; + Stripe.card.createToken(tokenData, (status, response) => { + if (response.error) { + console.error(response.error.message); + if (response.error.param) { + console.error(response.error.param); + } + } else { + success(response.card); + } + }); + } + }); +}); diff --git a/types/stripe/tsconfig.json b/types/stripe-v2/tsconfig.json similarity index 93% rename from types/stripe/tsconfig.json rename to types/stripe-v2/tsconfig.json index c15aeceae9..a40e816e5a 100644 --- a/types/stripe/tsconfig.json +++ b/types/stripe-v2/tsconfig.json @@ -18,6 +18,6 @@ }, "files": [ "index.d.ts", - "stripe-tests.ts" + "stripe-v2-tests.ts" ] } diff --git a/types/stripe/tslint.json b/types/stripe-v2/tslint.json similarity index 100% rename from types/stripe/tslint.json rename to types/stripe-v2/tslint.json diff --git a/types/stripe/index.d.ts b/types/stripe-v3/index.d.ts similarity index 93% rename from types/stripe/index.d.ts rename to types/stripe-v3/index.d.ts index f58d5e602f..2337e6adc2 100644 --- a/types/stripe/index.d.ts +++ b/types/stripe-v3/index.d.ts @@ -1,20 +1,30 @@ -// Type definitions for stripe 3.0 +// Type definitions for stripe-v3 3.0 // Project: https://stripe.com/ // Definitions by: Andy Hawkins // Eric J. Smith // Amrit Kahlon // Adam Cmiel // Justin Leider +// Kamil Gałuszka // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -export function Stripe(stripePublicKey: string): stripe.StripeStatic; +declare var Stripe: stripe.StripeStatic; -export namespace stripe { +declare namespace stripe { interface StripeStatic { + (publicKey: string): Stripe; + version: number; + } + + interface Stripe { elements(options?: elements.ElementsCreateOptions): elements.Elements; createToken(element: elements.Element, options?: TokenOptions): Promise; } + interface StripeOptions { + stripeAccount: string; + } + interface TokenOptions { name?: string; address_line1?: string; @@ -153,7 +163,7 @@ export namespace stripe { empty?: Style; invalid?: Style; }; - value?: string | {[objectKey: string]: string; }; + value?: string | { [objectKey: string]: string; }; } interface Style extends StyleOptions { diff --git a/types/stripe-v3/stripe-v3-tests.ts b/types/stripe-v3/stripe-v3-tests.ts new file mode 100644 index 0000000000..acf878d945 --- /dev/null +++ b/types/stripe-v3/stripe-v3-tests.ts @@ -0,0 +1,113 @@ +/// + +declare function describe(desc: string, fn: () => void): void; +declare function it(desc: string, fn: () => void): void; + +describe("Stripe", () => { + it("should excercise all Stripe API", () => { + const stripe = Stripe('public-key'); + const elements = stripe.elements(); + const style = { + base: { + color: '#32325d', + lineHeight: '24px', + fontFamily: 'Roboto, "Helvetica Neue", sans-serif', + fontSmoothing: 'antialiased', + fontSize: '16px', + '::placeholder': { + color: '#aab7c4' + } + }, + invalid: { + color: '#B71C1C', + iconColor: '#B71C1C' + } + }; + const card = elements.create('card', { hidePostalCode: true, style }); + card.mount(document.createElement('div')); + card.on('ready', () => { + console.log('ready'); + }); + card.on('change', (resp: stripe.elements.ElementChangeResponse) => { + console.log(resp.brand); + }); + stripe.createToken(card, { + name: 'Jimmy', + address_city: 'Toronto', + address_country: 'Canada' + }) + .then((result: stripe.TokenResponse) => { + console.log(result.token); + }, + (error: stripe.Error) => { + console.error(error); + }); + }); +}); + +describe("Stripe v2 & v3", () => { + it("should excercise all Stripe API", () => { + function success(card: stripe.StripeCard) { + console.log(card.brand && card.brand.toString()); + } + + const cardNumber = '4242424242424242'; + + const isValid = Stripe.validateCardNumber(cardNumber); + if (isValid) { + const tokenData: stripe.StripeCardTokenData = { + number: cardNumber, + exp_month: 1, + exp_year: 2100, + cvc: '111' + }; + Stripe.card.createToken(tokenData, (status, response) => { + if (response.error) { + console.error(response.error.message); + if (response.error.param) { + console.error(response.error.param); + } + } else { + success(response.card); + } + }); + } + const stripe = Stripe('public-key'); + const elements = stripe.elements(); + const style = { + base: { + color: '#32325d', + lineHeight: '24px', + fontFamily: 'Roboto, "Helvetica Neue", sans-serif', + fontSmoothing: 'antialiased', + fontSize: '16px', + '::placeholder': { + color: '#aab7c4' + } + }, + invalid: { + color: '#B71C1C', + iconColor: '#B71C1C' + } + }; + const card = elements.create('card', { hidePostalCode: true, style }); + card.mount(document.createElement('div')); + card.on('ready', () => { + console.log('ready'); + }); + card.on('change', (resp: stripe.elements.ElementChangeResponse) => { + console.log(resp.brand); + }); + stripe.createToken(card, { + name: 'Jimmy', + address_city: 'Toronto', + address_country: 'Canada' + }) + .then((result: stripe.TokenResponse) => { + console.log(result.token); + }, + (error: stripe.Error) => { + console.error(error); + }); + }); +}); diff --git a/types/stripe/v2/tsconfig.json b/types/stripe-v3/tsconfig.json similarity index 73% rename from types/stripe/v2/tsconfig.json rename to types/stripe-v3/tsconfig.json index 5917b8206d..4740cec2c1 100644 --- a/types/stripe/v2/tsconfig.json +++ b/types/stripe-v3/tsconfig.json @@ -8,19 +8,16 @@ "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, - "baseUrl": "../../", + "baseUrl": "../", "typeRoots": [ - "../../" + "../" ], "types": [], - "paths": { - "stripe": ["stripe/v2"] - }, "noEmit": true, "forceConsistentCasingInFileNames": true }, "files": [ "index.d.ts", - "stripe-tests.ts" + "stripe-v3-tests.ts" ] } diff --git a/types/stripe/v2/tslint.json b/types/stripe-v3/tslint.json similarity index 100% rename from types/stripe/v2/tslint.json rename to types/stripe-v3/tslint.json diff --git a/types/stripe/stripe-tests.ts b/types/stripe/stripe-tests.ts deleted file mode 100644 index f777c0eb34..0000000000 --- a/types/stripe/stripe-tests.ts +++ /dev/null @@ -1,39 +0,0 @@ -import {stripe, Stripe} from 'stripe'; - -const stripe = Stripe('public-key'); -const elements = stripe.elements(); -const style = { - base: { - color: '#32325d', - lineHeight: '24px', - fontFamily: 'Roboto, "Helvetica Neue", sans-serif', - fontSmoothing: 'antialiased', - fontSize: '16px', - '::placeholder': { - color: '#aab7c4' - } - }, - invalid: { - color: '#B71C1C', - iconColor: '#B71C1C' - } -}; -const card = elements.create('card', {hidePostalCode: true, style}); -card.mount(document.createElement('div')); -card.on('ready', () => { - console.log('ready'); -}); -card.on('change', (resp: stripe.elements.ElementChangeResponse) => { - console.log(resp.brand); -}); -stripe.createToken(card, { - name: 'Jimmy', - address_city: 'Toronto', - address_country: 'Canada' -}) -.then((result: stripe.TokenResponse) => { - console.log(result.token); -}, -(error: stripe.Error) => { - console.error(error); -}); diff --git a/types/stripe/v2/index.d.ts b/types/stripe/v2/index.d.ts deleted file mode 100644 index cc486b5d5b..0000000000 --- a/types/stripe/v2/index.d.ts +++ /dev/null @@ -1,170 +0,0 @@ -// Type definitions for stripe 2.x -// Project: https://stripe.com/ -// Definitions by: Andy Hawkins -// Eric J. Smith -// Amrit Kahlon -// Adam Cmiel -// Justin Leider -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -declare const Stripe: StripeStatic; - -interface StripeStatic { - applePay: StripeApplePay; - setPublishableKey(key: string): void; - validateCardNumber(cardNumber: string): boolean; - validateExpiry(month: string, year: string): boolean; - validateCVC(cardCVC: string): boolean; - cardType(cardNumber: string): StripeCardDataBrand; - getToken(token: string, responseHandler: (status: number, response: StripeCardTokenResponse) => void): void; - card: StripeCard; - createToken(data: StripeCardTokenData, responseHandler: (status: number, response: StripeCardTokenResponse) => void): void; - bankAccount: StripeBankAccount; -} - -interface StripeCardTokenData { - number: string; - exp_month?: number; - exp_year?: number; - exp?: string; - cvc?: string; - name?: string; - address_line1?: string; - address_line2?: string; - address_city?: string; - address_state?: string; - address_zip?: string; - address_country?: string; -} - -interface StripeTokenResponse { - id: string; - client_ip: string; - created: number; - livemode: boolean; - object: string; - type: string; - used: boolean; - error?: StripeError; -} - -interface StripeCardTokenResponse extends StripeTokenResponse { - card: StripeCard; -} - -interface StripeError { - type: string; - code: string; - message: string; - param?: string; -} - -type StripeCardDataBrand = 'Visa' | 'American Express' | 'MasterCard' | 'Discover' | 'JCB' | 'Diners Club' | 'Unknown'; - -type StripeCardDataFunding = 'credit' | 'debit' | 'prepaid' | 'unknown'; - -interface StripeCard { - object: string; - last4: string; - exp_month: number; - exp_year: number; - country?: string; - name?: string; - address_line1?: string; - address_line2?: string; - address_city?: string; - address_state?: string; - address_zip?: string; - address_country?: string; - brand?: StripeCardDataBrand; - funding?: StripeCardDataFunding; - createToken(data: StripeCardTokenData, responseHandler: (status: number, response: StripeCardTokenResponse) => void): void; - validateCardNumber(cardNumber: string): boolean; - validateExpiry(month: string, year: string): boolean; - validateCVC(cardCVC: string): boolean; -} - -interface StripeBankAccount { - createToken(params: StripeBankTokenParams, stripeResponseHandler: (status: number, response: StripeBankTokenResponse) => void): void; - validateRoutingNumber(routingNumber: number | string, countryCode: string): boolean; - validateAccountNumber(accountNumber: number | string, countryCode: string): boolean; -} - -interface StripeBankTokenParams { - country: string; - currency: string; - account_number: number | string; - routing_number?: number | string; - account_holder_name: string; - account_holder_type: string; -} - -interface StripeBankTokenResponse extends StripeTokenResponse { - bank_account: { - country: string; - bank_name: string; - last4: number; - validated: boolean; - object: string; - }; -} - -interface StripeApplePay { - checkAvailability(resopnseHandler: (result: boolean) => void): void; - buildSession(data: StripeApplePayPaymentRequest, - onSuccessHandler: (result: StripeApplePaySessionResult, completion: ((value: any) => void)) => void, - onErrorHanlder: (error: { message: string }) => void): any; -} - -type StripeApplePayBillingContactField = 'postalAddress' | 'name'; -type StripeApplePayShippingContactField = StripeApplePayBillingContactField | 'phone' | 'email'; -type StripeApplePayShipping = 'shipping' | 'delivery' | 'storePickup' | 'servicePickup'; - -interface StripeApplePayPaymentRequest { - billingContact: StripeApplePayPaymentContact; - countryCode: string; - currencyCode: string; - total: StripeApplePayLineItem; - lineItems?: StripeApplePayLineItem[]; - requiredBillingContactFields?: StripeApplePayBillingContactField[]; - requiredShippingContactFields?: StripeApplePayShippingContactField[]; - shippingContact?: StripeApplePayPaymentContact; - shippingMethods?: StripeApplePayShippingMethod[]; - shippingType?: StripeApplePayShipping[]; -} - -// https://developer.apple.com/reference/applepayjs/1916082-applepay_js_data_types -interface StripeApplePayLineItem { - type: 'pending' | 'final'; - label: string; - amount: number; -} - -interface StripeApplePaySessionResult { - token: StripeCardTokenResponse; - shippingContact?: StripeApplePayPaymentContact; - shippingMethod?: StripeApplePayShippingMethod; -} - -interface StripeApplePayShippingMethod { - label: string; - detail: string; - amount: number; - identifier: string; -} - -interface StripeApplePayPaymentContact { - emailAddress: string; - phoneNumber: string; - givenName: string; - familyName: string; - addressLines: string[]; - locality: string; - administrativeArea: string; - postalCode: string; - countryCode: string; -} - -// The Stripe client side APIs are not made available to package managers for direct installation. -// As explained compliance reasons. Source: https://github.com/stripe/stripe-node/blob/master/README.md#these-are-serverside-bindings-only -// A release date versioning schema is used to version these APIs. diff --git a/types/stripe/v2/stripe-tests.ts b/types/stripe/v2/stripe-tests.ts deleted file mode 100644 index 56e6343f5c..0000000000 --- a/types/stripe/v2/stripe-tests.ts +++ /dev/null @@ -1,25 +0,0 @@ -function success(card: StripeCard) { - console.log(card.brand && card.brand.toString()); -} - -const cardNumber = '4242424242424242'; - -const isValid = Stripe.validateCardNumber(cardNumber); -if (isValid) { - const tokenData: StripeCardTokenData = { - number: cardNumber, - exp_month: 1, - exp_year: 2100, - cvc: '111' - }; - Stripe.card.createToken(tokenData, (status, response) => { - if (response.error) { - console.error(response.error.message); - if (response.error.param) { - console.error(response.error.param); - } - } else { - success(response.card); - } - }); -} From 4d7e518e6e4a7e09836fbcf3ea419e5effc1c371 Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Sun, 16 Jul 2017 17:30:59 +0200 Subject: [PATCH 02/14] [iframe-resizer] add more specific and missing type definitions --- types/iframe-resizer/iframe-resizer-tests.ts | 49 ++- types/iframe-resizer/index.d.ts | 437 +++++++++++-------- 2 files changed, 286 insertions(+), 200 deletions(-) diff --git a/types/iframe-resizer/iframe-resizer-tests.ts b/types/iframe-resizer/iframe-resizer-tests.ts index d127f8bf36..186dc2ba47 100644 --- a/types/iframe-resizer/iframe-resizer-tests.ts +++ b/types/iframe-resizer/iframe-resizer-tests.ts @@ -1,32 +1,37 @@ -import {IFrameComponent, IFrameOptions, iframeResizer} from "iframe-resizer"; +import { IFrameComponent, IFrameOptions, iframeResizer } from "iframe-resizer"; function testOne(): void { - let iframe: HTMLIFrameElement = document.createElement('iframe'); - let options: IFrameOptions = {log: true}; - let components: IFrameComponent[] = iframeResizer(options, iframe); - if (components) { - components.forEach(component => console.log(component.iFrameResizer)); - } else { - console.log("No components"); - } + let iframe: HTMLIFrameElement = document.createElement('iframe'); + let options: IFrameOptions = {log: true}; + let components: IFrameComponent[] = iframeResizer(options, iframe); + if (components) { + components.forEach(component => console.log(component.iFrameResizer)); + } else { + console.log("No components"); + } } function testTwo(): void { - let iframe: HTMLIFrameElement = document.createElement('iframe'); - let components: IFrameComponent[] = iframeResizer({ - initCallback: () => { - console.log('Init'); - }, - closedCallback: () => { - console.log('Closed'); - } - }, iframe); - if (components) { - components.forEach(component => console.log(component.iFrameResizer)); - } else { - console.log("No components"); + let iframe: HTMLIFrameElement = document.createElement('iframe'); + let components: IFrameComponent[] = iframeResizer({ + initCallback: () => { + console.log('Init'); + }, + closedCallback: () => { + console.log('Closed'); } + }, iframe); + if (components) { + components.forEach(component => console.log(component.iFrameResizer)); + } else { + console.log("No components"); + } +} + +function testThree(): void { + iframeResizer({}, '.my-iframe'); } testOne(); testTwo(); +testThree(); diff --git a/types/iframe-resizer/index.d.ts b/types/iframe-resizer/index.d.ts index 1a05833692..3dd26dd391 100644 --- a/types/iframe-resizer/index.d.ts +++ b/types/iframe-resizer/index.d.ts @@ -6,191 +6,272 @@ // tslint:disable:prefer-method-signature // tslint:disable-next-line:no-single-declare-module declare module 'iframe-resizer' { - // tslint:disable-next-line:interface-name - interface IFrameObject { - close(): void; - moveToAnchor(anchor: string): void; - resize(): void; - sendMessage(message: any): void; - } + // tslint:disable-next-line:interface-name + interface IFrameObject { + close(): void; + moveToAnchor(anchor: string): void; + resize(): void; + sendMessage(message: any, targetOrigin?: string): void; + } - // tslint:disable-next-line:interface-name - interface IFrameComponent extends HTMLIFrameElement { - iFrameResizer: IFrameObject; - } + // tslint:disable-next-line:interface-name + interface IFrameComponent extends HTMLIFrameElement { + iFrameResizer: IFrameObject; + } - // tslint:disable-next-line:interface-name - interface IFrameOptions { - /** - * When enabled changes to the Window size or the DOM will cause the iFrame to resize to the new content size. - * Disable if using size method with custom dimensions. - */ - autoResize?: boolean; - /** - * Override the body background style in the iFrame. - */ - bodyBackground?: string; - /** - * Override the default body margin style in the iFrame. A string can be any valid value for the - * CSS margin attribute, for example '8px 3em'. A number value is converted into px. - */ - bodyMargin?: number; - /** - * When set to true, only allow incoming messages from the domain listed in the src property of the iFrame tag. - * If your iFrame navigates between different domains, ports or protocols; then you will need to - * provide an array of URLs or disable this option. - */ - checkOrigin?: boolean; - /** - * When enabled in page linking inside the iFrame and from the iFrame to the parent page will be enabled. - */ - inPageLinks?: boolean; - /** - * Height calculation method. - */ - heightCalculationMethod?: string; - /** - * Set iFrame Id - */ - id?: string; - /** - * In browsers that don't support mutationObserver, such as IE10, the library falls back to using - * setInterval, to check for changes to the page size. - */ - interval?: number; - /** - * Setting the log option to true will make the scripts in both the host page and the iFrame output - * everything they do to the JavaScript console so you can see the communication between the two scripts. - */ - log?: boolean; - /** - * Set maximum height of iFrame. - */ - maxHeight?: number; - /** - * Set maximum width of iFrame. - */ - maxWidth?: number; - /** - * Set minimum height of iFrame. - */ - minHeight?: number; - /** - * Set minimum width of iFrame. - */ - minWidth?: number; - /** - * Listen for resize events from the parent page, or the iFrame. Select the 'child' value if the iFrame - * can be resized independently of the browser window. Selecting this value can cause issues with some - * height calculation methods on mobile devices. - */ - resizeFrom?: string; - /** - * Enable scroll bars in iFrame. - */ - scrolling?: boolean; - /** - * Resize iFrame to content height. - */ - sizeHeight?: boolean; - /** - * Resize iFrame to content width. - */ - sizeWidth?: boolean; - /** - * Set the number of pixels the iFrame content size has to change by, before triggering a resize of the iFrame. - */ - tolerance?: number; - /** - * Width calculation method. - */ - widthCalculationMethod?: string; - /** - * Called when iFrame is closed via parentIFrame.close() or iframe.iframeResizer.close() methods. - */ - closedCallback?: (iframeId?: string) => void; - /** - * Initial setup callback function. - */ - initCallback?: (iframe?: IFrameComponent) => void; - /** - * Receive message posted from iFrame with the parentIFrame.sendMessage() method. - */ - messageCallback?: (data: IFrameMessageData) => void; - /** - * Function called after iFrame resized. Passes in messageData object containing the iFrame, height, width - * and the type of event that triggered the iFrame to resize. - */ - resizedCallback?: (data: IFrameResizedData) => void; - /** - * Called before the page is repositioned after a request from the iFrame, due to either an in page link, - * or a direct request from either parentIFrame.scrollTo() or parentIFrame.scrollToOffset(). - * If this callback function returns false, it will stop the library from repositioning the page, so that - * you can implement your own animated page scrolling instead. - */ - scrollCallback?: (data: IFrameScrollData) => boolean; - } + // tslint:disable-next-line:interface-name + interface IFrameOptions { + /** + * When enabled changes to the Window size or the DOM will cause the iFrame to resize to the new content size. + * Disable if using size method with custom dimensions. + */ + autoResize?: boolean; + /** + * Override the body background style in the iFrame. + */ + bodyBackground?: string; + /** + * Override the default body margin style in the iFrame. A string can be any valid value for the + * CSS margin attribute, for example '8px 3em'. A number value is converted into px. + */ + bodyMargin?: number; + /** + * When set to true, only allow incoming messages from the domain listed in the src property of the iFrame tag. + * If your iFrame navigates between different domains, ports or protocols; then you will need to + * provide an array of URLs or disable this option. + */ + checkOrigin?: boolean; + /** + * When enabled in page linking inside the iFrame and from the iFrame to the parent page will be enabled. + */ + inPageLinks?: boolean; + /** + * Height calculation method. + */ + heightCalculationMethod?: HeightCalculationMethod; + /** + * Set iFrame Id + */ + id?: string; + /** + * In browsers that don't support mutationObserver, such as IE10, the library falls back to using + * setInterval, to check for changes to the page size. + */ + interval?: number; + /** + * Setting the log option to true will make the scripts in both the host page and the iFrame output + * everything they do to the JavaScript console so you can see the communication between the two scripts. + */ + log?: boolean; + /** + * Set maximum height of iFrame. + */ + maxHeight?: number; + /** + * Set maximum width of iFrame. + */ + maxWidth?: number; + /** + * Set minimum height of iFrame. + */ + minHeight?: number; + /** + * Set minimum width of iFrame. + */ + minWidth?: number; + /** + * Listen for resize events from the parent page, or the iFrame. Select the 'child' value if the iFrame + * can be resized independently of the browser window. Selecting this value can cause issues with some + * height calculation methods on mobile devices. + */ + resizeFrom?: 'parent' | 'child'; + /** + * Enable scroll bars in iFrame. + */ + scrolling?: boolean | 'auto'; + /** + * Resize iFrame to content height. + */ + sizeHeight?: boolean; + /** + * Resize iFrame to content width. + */ + sizeWidth?: boolean; + /** + * Set the number of pixels the iFrame content size has to change by, before triggering a resize of the iFrame. + */ + tolerance?: number; + /** + * Width calculation method. + */ + widthCalculationMethod?: WidthCalculationMethod; + /** + * Called when iFrame is closed via parentIFrame.close() or iframe.iframeResizer.close() methods. + */ + closedCallback?: (iframeId: string) => void; + /** + * Initial setup callback function. + */ + initCallback?: (iframe: IFrameComponent) => void; + /** + * Receive message posted from iFrame with the parentIFrame.sendMessage() method. + */ + messageCallback?: (data: IFrameMessageData) => void; + /** + * Function called after iFrame resized. Passes in messageData object containing the iFrame, height, width + * and the type of event that triggered the iFrame to resize. + */ + resizedCallback?: (data: IFrameResizedData) => void; + /** + * Called before the page is repositioned after a request from the iFrame, due to either an in page link, + * or a direct request from either parentIFrame.scrollTo() or parentIFrame.scrollToOffset(). + * If this callback function returns false, it will stop the library from repositioning the page, so that + * you can implement your own animated page scrolling instead. + */ + scrollCallback?: (data: IFrameScrollData) => boolean; + } - // tslint:disable-next-line:interface-name - interface IFramePageOptions { - /** - * This option allows you to restrict the domain of the parent page, - * to prevent other sites mimicking your parent page. - */ - targetOrigin?: string; - /** - * Receive message posted from the parent page with the iframe.iFrameResizer.sendMessage() method. - */ - messageCallback?: (message: any) => void; - /** - * This function is called once iFrame-Resizer has been initialized after receiving a call from the parent page. - */ - readyCallback?: () => void; - /** - * These option can be used to override the option set in the parent page - */ - heightCalculationMethod?: string; - /** - * These option can be used to override the option set in the parent page - */ - widthCalculationMethod?: string; - } + // tslint:disable-next-line:interface-name + interface IFramePageOptions { + /** + * This option allows you to restrict the domain of the parent page, + * to prevent other sites mimicking your parent page. + */ + targetOrigin?: string; + /** + * Receive message posted from the parent page with the iframe.iFrameResizer.sendMessage() method. + */ + messageCallback?: (message: any) => void; + /** + * This function is called once iFrame-Resizer has been initialized after receiving a call from the parent page. + */ + readyCallback?: () => void; + /** + * These option can be used to override the option set in the parent page + */ + heightCalculationMethod?: HeightCalculationMethod | (() => number); + /** + * These option can be used to override the option set in the parent page + */ + widthCalculationMethod?: WidthCalculationMethod | (() => number); + } - // tslint:disable-next-line:interface-name - interface IFramePage { - autoResize(resize?: boolean): boolean; - close(): void; - getId(): string; - getPageInfo(callback: (data: any) => void | false): void; - scrollTo(x: number, y: number): void; - scrollToOffset(x: number, y: number): void; - sendMessage(message: any, targetOrigin: string): void; - setHeightCalculationMethod(method: string): void; - setWidthCalculationMethod(method: string): void; - setTargetOrigin(targetOrigin: string): void; - size(customHeight: string, customWidth: string): void; - } + type HeightCalculationMethod = 'bodyOffset' | 'bodyScroll' | 'documentElementOffset' | 'documentElementScroll' | + 'max' | 'min' | 'grow' | 'lowestElement' | 'taggedElement'; - // tslint:disable-next-line:interface-name - interface IFrameResizedData { - iframe: IFrameComponent; - height: number; - width: number; - type: string; - } + type WidthCalculationMethod = 'bodyOffset' | 'bodyScroll' | 'documentElementOffset' | 'documentElementScroll' | + 'max' | 'min' | 'scroll' | 'rightMostElement' | 'taggedElement'; - // tslint:disable-next-line:interface-name - interface IFrameMessageData { - iframe: IFrameComponent; - message: string; - } + // tslint:disable-next-line:interface-name + interface IFramePage { + /** + * Turn autoResizing of the iFrame on and off. Returns bool of current state. + */ + autoResize(resize?: boolean): boolean; + /** + * Remove the iFrame from the parent page. + */ + close(): void; + /** + * Returns the ID of the iFrame that the page is contained in. + */ + getId(): string; + /** + * Ask the containing page for its positioning coordinates. + * + * Your callback function will be recalled when the parent page is scrolled or resized. + * + * Pass false to disable the callback. + */ + getPageInfo(callback: ((data: PageInfo) => void) | false): void; + /** + * Scroll the parent page to the coordinates x and y + */ + scrollTo(x: number, y: number): void; + /** + * Scroll the parent page to the coordinates x and y relative to the position of the iFrame. + */ + scrollToOffset(x: number, y: number): void; + /** + * Send data to the containing page, message can be any data type that can be serialized into JSON. The `targetOrigin` + * option is used to restrict where the message is sent to; to stop an attacker mimicking your parent page. + * See the MDN documentation on postMessage for more details. + */ + sendMessage(message: any, targetOrigin?: string): void; + /** + * Change the method use to workout the height of the iFrame. + */ + setHeightCalculationMethod(method: HeightCalculationMethod): void; + /** + * Change the method use to workout the width of the iFrame. + */ + setWidthCalculationMethod(method: WidthCalculationMethod): void; + /** + * Set default target origin. + */ + setTargetOrigin(targetOrigin: string): void; + /** + * Manually force iFrame to resize. To use passed arguments you need first to disable the `autoResize` option to + * prevent auto resizing and enable the `sizeWidth` option if you wish to set the width. + */ + size(customHeight?: string, customWidth?: string): void; + } - // tslint:disable-next-line:interface-name - interface IFrameScrollData { - x: number; - y: number; - } + interface PageInfo { + /** + * The height of the iframe in pixels + */ + iframeHeight: number; + /** + * The width of the iframe in pixels + */ + iframeWidth: number; + /** + * The height of the viewport in pixels + */ + clientHeight: number; + /** + * The width of the viewport in pixels + */ + clientWidth: number; + /** + * The number of pixels between the left edge of the containing page and the left edge of the iframe + */ + offsetLeft: number; + /** + * The number of pixels between the top edge of the containing page and the top edge of the iframe + */ + offsetTop: number; + /** + * The number of pixels between the left edge of the iframe and the left edge of the iframe viewport + */ + scrollLeft: number; + /** + * The number of pixels between the top edge of the iframe and the top edge of the iframe viewport + */ + scrollTop: number; + } - function iframeResizer(options: IFrameOptions, target: HTMLElement): IFrameComponent[]; + // tslint:disable-next-line:interface-name + interface IFrameResizedData { + iframe: IFrameComponent; + height: number; + width: number; + type: string; + } + + // tslint:disable-next-line:interface-name + interface IFrameMessageData { + iframe: IFrameComponent; + message: string; + } + + // tslint:disable-next-line:interface-name + interface IFrameScrollData { + x: number; + y: number; + } + + function iframeResizer(options: IFrameOptions, target: string | HTMLElement): IFrameComponent[]; } // tslint:enable:prefer-method-signature From b4f85d23f5c117ffcafddfd6fe1028da126f72ef Mon Sep 17 00:00:00 2001 From: Gilbert Handy Date: Mon, 17 Jul 2017 17:36:35 -0400 Subject: [PATCH 03/14] Added types for geodesy latlon-spherical.js --- types/geodesy/geodesy-tests.ts | 52 +++++++++++++++++++++++++++++++++- types/geodesy/index.d.ts | 25 ++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/types/geodesy/geodesy-tests.ts b/types/geodesy/geodesy-tests.ts index e3ce4f627a..984b8e80c2 100644 --- a/types/geodesy/geodesy-tests.ts +++ b/types/geodesy/geodesy-tests.ts @@ -4,7 +4,7 @@ import { Dms, Vector3d, OsGridRef, - LatLonEllipsoidal as LatLon } from 'geodesy'; + LatLonEllipsoidal as LatLon, LatLonSpherical } from 'geodesy'; /** * Mgrs @@ -115,3 +115,53 @@ OsGridRef.latLonToOsGrid(latlon); OsGridRef.osGridToLatLon(gridref); OsGridRef.osGridToLatLon(gridref, LatLon.datum.OSGB36); OsGridRef.parse('TG 51409 13177'); + +/** + * LatLonSpherical + */ +const point1 = new LatLonSpherical(52.205, 0.119); +const point2 = new LatLonSpherical(48.857, 2.351); + +point1.distanceTo(point2); // 404.3 km +point1.distanceTo(point2, 6371e3); // 404.3 km +point1.bearingTo(point2); // 156.2° +point1.finalBearingTo(point2); // 157.9° +point1.midpointTo(point2); // 50.5363°N, 001.2746°E +point1.intermediatePointTo(point2, 0.25); // 51.3721°N, 000.7073°E +point1.destinationPoint(7794, 300.7); // 51.5135°N, 000.0983°W +point1.destinationPoint(7794, 300.7, 6371e3); // 51.5135°N, 000.0983°W + +const ctCurrent = new LatLonSpherical(53.2611, -0.7972); +const ct1 = new LatLonSpherical(53.3206, -1.7297); +const ct2 = new LatLonSpherical(53.1887, 0.1334); +ctCurrent.crossTrackDistanceTo(ct1, ct2); // -307.5 m +ctCurrent.crossTrackDistanceTo(ct1, ct2, 6371e3); // -307.5 m + +point1.maxLatitude(156); + +const rhumb1 = new LatLonSpherical(51.127, 1.338); +const rhumb2 = new LatLonSpherical(50.964, 1.853); +rhumb1.rhumbDistanceTo(rhumb2); // 40.31 km +rhumb1.rhumbDistanceTo(rhumb2, 6371e3); // 40.31 km +rhumb1.rhumbBearingTo(rhumb2); // 116.7° +rhumb1.rhumbDestinationPoint(40300, 116.7); // 50.9642°N, 001.8530°E +rhumb1.rhumbDestinationPoint(40300, 116.7, 6371e3); // 50.9642°N, 001.8530°E +rhumb1.rhumbMidpointTo(rhumb2); // 51.0455°N, 001.5957°E + +const eq1 = new LatLonSpherical(52.205, 0.119); +const eq2 = new LatLonSpherical(52.205, 0.119); +eq1.equals(eq2); // true + +eq1.toString(); +eq1.toString('dm'); +eq1.toString('d', 0); + +// Static functions +const brng1 = 108.547; +const brng2 = 32.435; +LatLonSpherical.intersection(point1, brng1, point2, brng2); // 50.9078°N, 004.5084°E +LatLonSpherical.crossingParallels(point1, point2, 30); + +const polygon = [new LatLonSpherical(0, 0), new LatLonSpherical(1, 0), new LatLonSpherical(0, 1)]; +LatLonSpherical.areaOf(polygon); // 6.18e9 m² +LatLonSpherical.areaOf(polygon, 6371e3); // 6.18e9 m² diff --git a/types/geodesy/index.d.ts b/types/geodesy/index.d.ts index 12adb4d7c1..be4d183526 100644 --- a/types/geodesy/index.d.ts +++ b/types/geodesy/index.d.ts @@ -1,6 +1,7 @@ // Type definitions for geodesy 1.1 // Project: https://github.com/chrisveness/geodesy // Definitions by: Denis Carriere + Gilbert Handy // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped export type format = 'd' | 'dm' | 'dms'; @@ -147,3 +148,27 @@ export class LatLonEllipsoidal { static datum: Datums; static ellipsoid: Ellipsoids; } + +export class LatLonSpherical { + lat: number; + lon: number; + constructor(lat: number, lon: number) + distanceTo(point: LatLonSpherical, radius?: number): number; + bearingTo(point: LatLonSpherical): number; + finalBearingTo(point: LatLonSpherical): number; + midpointTo(point: LatLonSpherical): number; + intermediatePointTo(point: LatLonSpherical, fraction: number): LatLonSpherical; + destinationPoint(distance: number, bearing: number, radius?: number): LatLonSpherical; + static intersection(point1: LatLonSpherical, bearing1: number, point2: LatLonSpherical, bearing2: number): LatLonSpherical; + crossTrackDistanceTo(pathStart: LatLonSpherical, pathEnd: LatLonSpherical, radius?: number): number; + maxLatitude(bearing: number): number; + static crossingParallels(point1: LatLonSpherical, point2: LatLonSpherical, latitude: number): any; + rhumbDistanceTo(point: LatLonSpherical, radius?: number): number; + rhumbBearingTo(point: LatLonSpherical): number; + rhumbDestinationPoint(distance: number, bearing: number, radius?: number): LatLonSpherical; + rhumbMidpointTo(point: LatLonSpherical): LatLonSpherical; + equals(point: LatLonSpherical): boolean; + static areaOf(polygon: LatLonSpherical[], radius?: number): number; + toString(format?: string, dp?: number): string; +} + From 03136f65c818d5f2d88e1c68b0162c28d0f95265 Mon Sep 17 00:00:00 2001 From: Gilbert Handy Date: Mon, 17 Jul 2017 17:51:40 -0400 Subject: [PATCH 04/14] Fix formatting issues --- types/geodesy/index.d.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/types/geodesy/index.d.ts b/types/geodesy/index.d.ts index be4d183526..1d8ef3e110 100644 --- a/types/geodesy/index.d.ts +++ b/types/geodesy/index.d.ts @@ -1,7 +1,7 @@ // Type definitions for geodesy 1.1 // Project: https://github.com/chrisveness/geodesy // Definitions by: Denis Carriere - Gilbert Handy +// Gilbert Handy // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped export type format = 'd' | 'dm' | 'dms'; @@ -171,4 +171,3 @@ export class LatLonSpherical { static areaOf(polygon: LatLonSpherical[], radius?: number): number; toString(format?: string, dp?: number): string; } - From 4753cb27edd3ec639b46da8f1ac85884cc00e522 Mon Sep 17 00:00:00 2001 From: Benjamin Fox Date: Tue, 18 Jul 2017 10:26:14 +1200 Subject: [PATCH 05/14] Add basic method name type checking to sinon.spy and sinon.stub --- types/sinon/index.d.ts | 8 ++++---- types/sinon/sinon-tests.ts | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/types/sinon/index.d.ts b/types/sinon/index.d.ts index 75e87baae1..30a64b9d81 100644 --- a/types/sinon/index.d.ts +++ b/types/sinon/index.d.ts @@ -96,8 +96,8 @@ declare namespace Sinon { interface SinonSpyStatic { (): SinonSpy; - (func: any): SinonSpy; - (obj: any, method: string): SinonSpy; + (func: Function): SinonSpy; + (obj: T, method: keyof T): SinonSpy; } interface SinonStatic { @@ -153,8 +153,8 @@ declare namespace Sinon { interface SinonStubStatic { (): SinonStub; (obj: any): SinonStub; - (obj: any, method: string): SinonStub; - (obj: any, method: string, func: any): SinonStub; + (obj: T, method: keyof T): SinonStub; + (obj: T, method: keyof T, func: Function): SinonStub; } interface SinonStatic { diff --git a/types/sinon/sinon-tests.ts b/types/sinon/sinon-tests.ts index 406c790a2b..cd48901dd0 100644 --- a/types/sinon/sinon-tests.ts +++ b/types/sinon/sinon-tests.ts @@ -30,7 +30,7 @@ function testTwo() { function testThree() { let obj = { thisObj: true }; - let callback = sinon.spy({}, "method"); + let callback = sinon.spy({}, "method"); let proxy = once(callback); proxy.call(obj, callback, 1, 2, 3); if (callback.calledOn(obj)) { console.log("test3 calledOn success"); } else { console.log("test3 calledOn failure"); } @@ -168,7 +168,7 @@ function testSetMatcher() { } function testGetterStub() { - const myObj: any = { + const myObj = { prop: 'foo' }; @@ -177,7 +177,7 @@ function testGetterStub() { } function testSetterStub() { - const myObj: any = { + const myObj = { prop: 'foo', prop2: 'bar' }; @@ -187,7 +187,7 @@ function testSetterStub() { } function testValueStub() { - const myObj: any = { + const myObj = { prop: 'foo' }; From 2cde2fb1edb6952211f4b555583810c106dadb94 Mon Sep 17 00:00:00 2001 From: Angus Jones Date: Tue, 18 Jul 2017 10:00:28 +1000 Subject: [PATCH 06/14] Remove [index: string]: any; in IRootScopeService To bring it into line with both the documentation (https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/angular#a-word-on-scope-and-assigning-new-members) and the general guidelines (https://github.com/Microsoft/TypeScript/issues/12596#issuecomment-299976171). --- types/angular/index.d.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/types/angular/index.d.ts b/types/angular/index.d.ts index b37e1ba421..fcfcf183e2 100644 --- a/types/angular/index.d.ts +++ b/types/angular/index.d.ts @@ -451,8 +451,6 @@ declare namespace angular { * see https://docs.angularjs.org/api/ng/type/$rootScope.Scope and https://docs.angularjs.org/api/ng/service/$rootScope */ interface IRootScopeService { - [index: string]: any; - $apply(): any; $apply(exp: string): any; $apply(exp: (scope: IScope) => any): any; From 3a9efcb75b2cf81bb4b876f4db1ee394a10983d2 Mon Sep 17 00:00:00 2001 From: Angus Date: Tue, 18 Jul 2017 11:50:28 +1000 Subject: [PATCH 07/14] Fixed failing tests --- .../angular-clipboard-tests.ts | 6 +++++- types/angular-locker/angular-locker-tests.ts | 7 ++++++- .../angular-material/angular-material-tests.ts | 18 +++++++++++------- types/angular-meteor/angular-meteor-tests.ts | 2 ++ types/angular-resource/index.d.ts | 4 ++-- .../angular-ui-scroll-tests.ts | 6 +++++- 6 files changed, 31 insertions(+), 12 deletions(-) diff --git a/types/angular-clipboard/angular-clipboard-tests.ts b/types/angular-clipboard/angular-clipboard-tests.ts index b043a85d5a..00c5074ec5 100644 --- a/types/angular-clipboard/angular-clipboard-tests.ts +++ b/types/angular-clipboard/angular-clipboard-tests.ts @@ -1,8 +1,12 @@ import * as angular from "angular"; import {ClipboardService} from "angular-clipboard"; +interface TestScope extends ng.IScope { + [index: string]: any; +} + const app = angular.module('testModule', ['angular-clipboard']); -app.controller('TestController', ($scope: ng.IScope, clipboard: ClipboardService) => { +app.controller('TestController', ($scope: TestScope, clipboard: ClipboardService) => { $scope['testCopy'] = () => { if (clipboard.supported) { clipboard.copyText('hiiiiiii'); diff --git a/types/angular-locker/angular-locker-tests.ts b/types/angular-locker/angular-locker-tests.ts index a82f6a86cb..368dd1d308 100644 --- a/types/angular-locker/angular-locker-tests.ts +++ b/types/angular-locker/angular-locker-tests.ts @@ -1,5 +1,10 @@ import * as angular from 'angular'; + +interface TestScope extends angular.IScope { + [index: string]: any; +} + angular .module('angular-locker-tests', ['angular-locker']) .config(['lockerProvider', function config(lockerProvider: angular.locker.ILockerProvider) { @@ -13,7 +18,7 @@ angular lockerProvider.defaults(lockerSettings); }]) -.controller('LockerController', ['$scope', 'locker', function ($scope: angular.IScope, locker: angular.locker.ILockerService) { +.controller('LockerController', ['$scope', 'locker', function ($scope: TestScope, locker: angular.locker.ILockerService) { locker.put('someKey', 'someVal'); // put an item into session storage diff --git a/types/angular-material/angular-material-tests.ts b/types/angular-material/angular-material-tests.ts index d1af7c8159..5766a81975 100644 --- a/types/angular-material/angular-material-tests.ts +++ b/types/angular-material/angular-material-tests.ts @@ -1,5 +1,9 @@ const myApp = angular.module('testModule', ['ngMaterial']); +interface TestScope extends ng.IScope { + [index: string]: any; +} + myApp.config(( $mdThemingProvider: ng.material.IThemingProvider, $mdIconProvider: ng.material.IIconProvider, @@ -50,7 +54,7 @@ myApp.config(( }); }); -myApp.controller('BottomSheetController', ($scope: ng.IScope, $mdBottomSheet: ng.material.IBottomSheetService, $q: ng.IQService) => { +myApp.controller('BottomSheetController', ($scope: TestScope, $mdBottomSheet: ng.material.IBottomSheetService, $q: ng.IQService) => { $scope['openBottomSheet'] = () => { $mdBottomSheet.show({ template: 'Hello!', @@ -84,7 +88,7 @@ myApp.controller('BottomSheetController', ($scope: ng.IScope, $mdBottomSheet: ng $scope['cancelBottomSheet'] = $mdBottomSheet.cancel.bind($mdBottomSheet, 'cancel'); }); -myApp.controller('ColorController', ($scope: ng.IScope, $mdColor: ng.material.IColorService) => { +myApp.controller('ColorController', ($scope: TestScope, $mdColor: ng.material.IColorService) => { const colorExpression: ng.material.IColorExpression = { color: '#FFFFFF' }; const element: Element = new Element(); @@ -99,7 +103,7 @@ myApp.controller('ColorController', ($scope: ng.IScope, $mdColor: ng.material.IC }; }); -myApp.controller('DialogController', ($scope: ng.IScope, $mdDialog: ng.material.IDialogService, $q: ng.IQService) => { +myApp.controller('DialogController', ($scope: TestScope, $mdDialog: ng.material.IDialogService, $q: ng.IQService) => { $scope['openDialog'] = () => { $mdDialog.show({ template: 'Hello!' @@ -201,7 +205,7 @@ class IconDirective implements ng.IDirective { } myApp.directive('icon-directive', ($mdIcon: ng.material.IIcon) => new IconDirective($mdIcon)); -myApp.controller('MediaController', ($scope: ng.IScope, $mdMedia: ng.material.IMedia) => { +myApp.controller('MediaController', ($scope: TestScope, $mdMedia: ng.material.IMedia) => { $scope.$watch(() => $mdMedia('lg'), (big: boolean) => { $scope['bigScreen'] = big; }); @@ -210,7 +214,7 @@ myApp.controller('MediaController', ($scope: ng.IScope, $mdMedia: ng.material.IM $scope['anotherCustom'] = $mdMedia('max-width: 300px'); }); -myApp.controller('SidenavController', ($scope: ng.IScope, $mdSidenav: ng.material.ISidenavService) => { +myApp.controller('SidenavController', ($scope: TestScope, $mdSidenav: ng.material.ISidenavService) => { const componentId = 'left'; $scope['toggle'] = () => $mdSidenav(componentId).toggle(); $scope['open'] = () => $mdSidenav(componentId).open(); @@ -229,7 +233,7 @@ myApp.controller('SidenavController', ($scope: ng.IScope, $mdSidenav: ng.materia $scope['onClose'] = $mdSidenav(componentId).onClose(() => { }); }); -myApp.controller('ToastController', ($scope: ng.IScope, $mdToast: ng.material.IToastService, $q: ng.IQService) => { +myApp.controller('ToastController', ($scope: TestScope, $mdToast: ng.material.IToastService, $q: ng.IQService) => { $scope['openToast'] = () => { $mdToast.show($mdToast.simple().textContent('Hello!')); $mdToast.updateTextContent('New Content'); @@ -260,7 +264,7 @@ myApp.controller('ToastController', ($scope: ng.IScope, $mdToast: ng.material.IT }; }); -myApp.controller('PanelController', ($scope: ng.IScope, $mdPanel: ng.material.IPanelService, $q: ng.IQService) => { +myApp.controller('PanelController', ($scope: TestScope, $mdPanel: ng.material.IPanelService, $q: ng.IQService) => { $scope['createPanel'] = () => { const config: ng.material.IPanelConfig = { id: 'myPanel', diff --git a/types/angular-meteor/angular-meteor-tests.ts b/types/angular-meteor/angular-meteor-tests.ts index 6a379b8bac..21cbb4e3a3 100644 --- a/types/angular-meteor/angular-meteor-tests.ts +++ b/types/angular-meteor/angular-meteor-tests.ts @@ -27,6 +27,8 @@ interface CustomScope extends angular.meteor.IScope { removeAll: () => void; removeAuto: (todo: ITodo) => void; toSticky: (todo: ITodo) => void; + + picture: any; } var Todos = new Mongo.Collection('todos'); diff --git a/types/angular-resource/index.d.ts b/types/angular-resource/index.d.ts index b95911ae2c..4bdc8cc007 100644 --- a/types/angular-resource/index.d.ts +++ b/types/angular-resource/index.d.ts @@ -53,14 +53,14 @@ declare module 'angular' { interface IActionHash { [action: string]: IActionDescriptor; } - + interface IResourceResponse { config: any; data: any; headers: any; resource: any; status: number; - statusText: string + statusText: string; } interface IResourceInterceptor { diff --git a/types/angular-ui-scroll/angular-ui-scroll-tests.ts b/types/angular-ui-scroll/angular-ui-scroll-tests.ts index e226b664bc..9be5609d16 100644 --- a/types/angular-ui-scroll/angular-ui-scroll-tests.ts +++ b/types/angular-ui-scroll/angular-ui-scroll-tests.ts @@ -23,8 +23,12 @@ namespace application { myApp.factory('DatasourceTest', factory); + interface TestScope extends ng.IScope { + [index: string]: any; + } + // demo/examples/adapter - myApp.controller('mainController', ['$scope', 'DatasourceTest', function($scope: ng.IScope, datasource: DatasourceTest) { + myApp.controller('mainController', ['$scope', 'DatasourceTest', function($scope: TestScope, datasource: DatasourceTest) { var firstListAdapter: ng.ui.IScrollAdapter, secondListAdapter: ng.ui.IScrollAdapter; $scope['datasource'] = datasource; From 6c49782ce42d0fea3b018c3c23761fc5ad0c279e Mon Sep 17 00:00:00 2001 From: william chang Date: Tue, 18 Jul 2017 15:55:50 +0800 Subject: [PATCH 08/14] [aws-lambda] S3CreateEvent.Records should be Array instead of Tuple --- types/aws-lambda/aws-lambda-tests.ts | 69 ++++++++++++++------------- types/aws-lambda/index.d.ts | 71 ++++++++++++++-------------- 2 files changed, 71 insertions(+), 69 deletions(-) diff --git a/types/aws-lambda/aws-lambda-tests.ts b/types/aws-lambda/aws-lambda-tests.ts index 7f8b8fabdd..10b4fa1073 100644 --- a/types/aws-lambda/aws-lambda-tests.ts +++ b/types/aws-lambda/aws-lambda-tests.ts @@ -22,43 +22,44 @@ var snsEvtRec: AWSLambda.SNSEventRecord; var snsMsg: AWSLambda.SNSMessage; var snsMsgAttr: AWSLambda.SNSMessageAttribute; var snsMsgAttrs: AWSLambda.SNSMessageAttributes; -var S3CreateEvent: AWSLambda.S3CreateEvent = { - Records: [{ - eventVersion: 'string', - eventSource: 'string', - awsRegion: 'string', - eventTime: 'string', - eventName: 'string', - userIdentity: { - principalId: 'string' - }, - requestParameters: { - sourceIPAddress: 'string' - }, - responseElements: { - 'x-amz-request-id': 'string', - 'x-amz-id-2': 'string' - }, - s3: { - s3SchemaVersion: 'string', - configurationId: 'string', - bucket: { - name: 'string', - ownerIdentity: { - principalId: 'string' - }, - arn: 'string' +var S3EvtRec: AWSLambda.S3EventRecord = { + eventVersion: '2.0', + eventSource: 'aws:s3', + awsRegion: 'us-east-1', + eventTime: '1970-01-01T00:00:00.000Z', + eventName: 'ObjectCreated:Put', + userIdentity: { + principalId: 'AIDAJDPLRKLG7UEXAMPLE' + }, + requestParameters:{ + sourceIPAddress: '127.0.0.1' + }, + responseElements: { + 'x-amz-request-id': 'C3D13FE58DE4C810', + 'x-amz-id-2': 'FMyUVURIY8/IgAtTv8xRjskZQpcIZ9KG4V5Wp6S7S/JRWeUWerMUE5JgHvANOjpD' + }, + s3: { + s3SchemaVersion: '1.0', + configurationId: 'testConfigRule', + bucket: { + name: 'mybucket', + ownerIdentity: { + principalId: 'A3NL1KOZZKExample' }, - object: { - key: 'string', - size: 1, - eTag: 'string', - versionId: 'string', - sequencer: 'string' - } + arn: 'arn:aws:s3:::mybucket' + }, + object: { + key: 'HappyFace.jpg', + size: 1024, + eTag: 'd41d8cd98f00b204e9800998ecf8427e', + versionId: '096fKKXTRTtl3on89fVO.nfljtsv6qko', + sequencer: '0055AED6DCD90281E5' } } - ] +}; + +var S3CreateEvent: AWSLambda.S3CreateEvent = { + Records: [S3EvtRec] }; var cognitoUserPoolEvent: AWSLambda.CognitoUserPoolEvent; var cloudformationCustomResourceEvent: AWSLambda.CloudFormationCustomResourceEvent; diff --git a/types/aws-lambda/index.d.ts b/types/aws-lambda/index.d.ts index df8effb82b..1da094ac46 100644 --- a/types/aws-lambda/index.d.ts +++ b/types/aws-lambda/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for AWS Lambda // Project: http://docs.aws.amazon.com/lambda -// Definitions by: James Darbyshire , Michael Skarum , Stef Heyenrath , Toby Hede , Rich Buggy , Yoriki Yamaguchi +// Definitions by: James Darbyshire , Michael Skarum , Stef Heyenrath , Toby Hede , Rich Buggy , Yoriki Yamaguchi , wwwy3y3 // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // API Gateway "event" @@ -85,43 +85,44 @@ interface SNSEvent { * S3Create event * https://docs.aws.amazon.com/AmazonS3/latest/dev/notification-content-structure.html */ -interface S3CreateEvent { - Records: [{ - eventVersion: string; - eventSource: string; - awsRegion: string - eventTime: string; - eventName: string; - userIdentity: { - principalId: string; - }, - requestParameters: { - sourceIPAddress: string; - }, - responseElements: { - 'x-amz-request-id': string; - 'x-amz-id-2': string; - }, - s3: { - s3SchemaVersion: string; - configurationId: string; - bucket: { - name: string; - ownerIdentity: { - principalId: string; - }, - arn: string; +interface S3EventRecord { + eventVersion: string; + eventSource: string; + awsRegion: string + eventTime: string; + eventName: string; + userIdentity: { + principalId: string; + }, + requestParameters: { + sourceIPAddress: string; + }, + responseElements: { + 'x-amz-request-id': string; + 'x-amz-id-2': string; + }, + s3: { + s3SchemaVersion: string; + configurationId: string; + bucket: { + name: string; + ownerIdentity: { + principalId: string; }, - object: { - key: string; - size: number; - eTag: string; - versionId: string; - sequencer: string; - } + arn: string; + }, + object: { + key: string; + size: number; + eTag: string; + versionId: string; + sequencer: string; } } - ]; +} + +interface S3CreateEvent { + Records: Array; } /** From 352aa44c0ae255a06446286a68ba64eeff101a00 Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Sat, 15 Jul 2017 12:27:54 +0200 Subject: [PATCH 09/14] Add react helpers to babel-types --- types/babel-types/babel-types-tests.ts | 27 ++++++++++++++++++++++++++ types/babel-types/index.d.ts | 13 +++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/types/babel-types/babel-types-tests.ts b/types/babel-types/babel-types-tests.ts index 5974a64885..394603ab31 100644 --- a/types/babel-types/babel-types-tests.ts +++ b/types/babel-types/babel-types-tests.ts @@ -29,3 +29,30 @@ t.assertBinaryExpression(ast); t.assertBinaryExpression(ast, { operator: "*" }); var exp: t.Expression = t.nullLiteral(); + +// React examples: + +// https://github.com/babel/babel/blob/4e50b2d9d9c376cee7a2cbf56553fe5b982ea53c/packages/babel-plugin-transform-react-inline-elements/src/index.js#L61 +traverse(ast, { + JSXElement(path, file) { + const { node } = path; + const open = node.openingElement; + + // init + const type = open.name; + + let newType: t.StringLiteral; + if (t.isJSXIdentifier(type) && t.react.isCompatTag(type.name)) { + newType = t.stringLiteral(type.name); + } + + const args: any[] = []; + if (node.children.length) { + const children = t.react.buildChildren(node); + args.push( + t.unaryExpression("void", t.numericLiteral(0), true), + ...children, + ); + } + } +}); diff --git a/types/babel-types/index.d.ts b/types/babel-types/index.d.ts index 77ea8b54de..c3f77b559f 100644 --- a/types/babel-types/index.d.ts +++ b/types/babel-types/index.d.ts @@ -1,6 +1,8 @@ -// Type definitions for babel-types v6.7 +// Type definitions for babel-types v6.25 // Project: https://github.com/babel/babel/tree/master/packages/babel-types -// Definitions by: Troy Gerwien , Sam Baxter +// Definitions by: Troy Gerwien +// Sam Baxter +// Marvin Hagemeister // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped export interface Comment { @@ -1226,6 +1228,13 @@ export function isUser(node: Object, opts?: Object): boolean; export function isGenerated(node: Object, opts?: Object): boolean; export function isPure(node: Object, opts?: Object): boolean; +// React specific +interface ReactHelpers { + isCompatTag(tagName?: string): boolean; + buildChildren(node: Object): Object[]; +} +export const react: ReactHelpers; + export function assertArrayExpression(node: Object, opts?: Object): void; export function assertAssignmentExpression(node: Object, opts?: Object): void; export function assertBinaryExpression(node: Object, opts?: Object): void; From a3819eec0763fe88008dfc073c30695681c4974a Mon Sep 17 00:00:00 2001 From: Lukasz Zak Date: Tue, 18 Jul 2017 13:04:48 +0200 Subject: [PATCH 10/14] [mongoose] Add missing property for >=4.1.1 version DeprecationWarning: `open()` is deprecated in mongoose >= 4.11.0, use `openUri()` instead, or set the `useMongoClient` option if using `connect()` or `createConnection()`. See http://mongoosejs.com/docs/connections.html#use-mongo-client --- types/mongoose/index.d.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/types/mongoose/index.d.ts b/types/mongoose/index.d.ts index 12da9c180b..3c48f309f6 100644 --- a/types/mongoose/index.d.ts +++ b/types/mongoose/index.d.ts @@ -1,6 +1,6 @@ -// Type definitions for Mongoose 4.7.0 +// Type definitions for Mongoose 4.7.1 // Project: http://mongoosejs.com/ -// Definitions by: simonxca , horiuchi , sindrenm +// Definitions by: simonxca , horiuchi , sindrenm , lukasz-zak // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 @@ -388,6 +388,9 @@ declare module "mongoose" { /** sets the underlying driver's promise library (see http://mongodb.github.io/node-mongodb-native/2.1/api/MongoClient.html) */ promiseLibrary?: any; + + /** See http://mongoosejs.com/docs/connections.html#use-mongo-client **/ + useMongoClient?: boolean; } interface ConnectionOptions extends From 226ef5f14c338f1435fa2c6ca75c3e97e3a7ae48 Mon Sep 17 00:00:00 2001 From: Leonard Thieu Date: Tue, 18 Jul 2017 09:13:58 -0400 Subject: [PATCH 11/14] [jquery] Revert isEmptyObject() to returning boolean. While the type guard does narrow a value's type to an empty object, the interesting case is when the type is not an empty object. TypeScript narrows the type to never in that case which makes the type guard not very useful. --- types/jquery/index.d.ts | 2 +- types/jquery/jquery-tests.ts | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/types/jquery/index.d.ts b/types/jquery/index.d.ts index 4ebb4692f5..2fd196fd41 100644 --- a/types/jquery/index.d.ts +++ b/types/jquery/index.d.ts @@ -587,7 +587,7 @@ interface JQueryStatic { * @see {@link https://api.jquery.com/jQuery.isEmptyObject/} * @since 1.4 */ - isEmptyObject(obj: any): obj is {}; + isEmptyObject(obj: any): boolean; /** * Determine if the argument passed is a JavaScript function object. * diff --git a/types/jquery/jquery-tests.ts b/types/jquery/jquery-tests.ts index 01cc4a345e..0485d05351 100644 --- a/types/jquery/jquery-tests.ts +++ b/types/jquery/jquery-tests.ts @@ -627,12 +627,8 @@ function JQueryStatic() { } function isEmptyObject() { - function type_guard(obj: object) { - if ($.isEmptyObject(obj)) { - // $ExpectType {} - obj; - } - } + // $ExpectType boolean + $.isEmptyObject({}); } function isFunction() { From ec2158f2d6f34297a2dc52b93537cd089cc68285 Mon Sep 17 00:00:00 2001 From: Leonard Thieu Date: Tue, 18 Jul 2017 09:22:02 -0400 Subject: [PATCH 12/14] [jquery] Add tests for type of a type guard in the not case. Note that isPlainObject() fails the not case in the same manner that isEmptyObject() does. This might warrant changing it to return a boolean. However, unlike isEmptyObject(), isPlainObject() can be useful when the object is a plain object. --- types/jquery/jquery-tests.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/types/jquery/jquery-tests.ts b/types/jquery/jquery-tests.ts index 0485d05351..4bbe9c553e 100644 --- a/types/jquery/jquery-tests.ts +++ b/types/jquery/jquery-tests.ts @@ -622,6 +622,9 @@ function JQueryStatic() { if ($.isArray(obj)) { // $ExpectType any[] obj; + } else { + // $ExpectType object + obj; } } } @@ -636,6 +639,9 @@ function JQueryStatic() { if ($.isFunction(obj)) { // $ExpectType Function obj; + } else { + // $ExpectType object + obj; } } } @@ -645,6 +651,9 @@ function JQueryStatic() { if ($.isNumeric(obj)) { // $ExpectType (true & number) | (false & number) obj; + } else { + // $ExpectType boolean + obj; } } } @@ -663,6 +672,9 @@ function JQueryStatic() { if ($.isWindow(obj)) { // $ExpectType Window obj; + } else { + // $ExpectType object + obj; } } } From f234366096fd8dce2d466ee753c32cd8619ab0ca Mon Sep 17 00:00:00 2001 From: Leonard Thieu Date: Tue, 18 Jul 2017 10:35:27 -0400 Subject: [PATCH 13/14] [angular-resource] Lint. --- types/angular-resource/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/angular-resource/index.d.ts b/types/angular-resource/index.d.ts index b95911ae2c..4bdc8cc007 100644 --- a/types/angular-resource/index.d.ts +++ b/types/angular-resource/index.d.ts @@ -53,14 +53,14 @@ declare module 'angular' { interface IActionHash { [action: string]: IActionDescriptor; } - + interface IResourceResponse { config: any; data: any; headers: any; resource: any; status: number; - statusText: string + statusText: string; } interface IResourceInterceptor { From a790cd60fcc0a518659fa0b966b026f212b28abd Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Tue, 18 Jul 2017 09:13:17 -0700 Subject: [PATCH 14/14] Revert "react-transition-group Added {} state to remedy Component Requires 2 type arguments" --- types/react-transition-group/CSSTransition.d.ts | 2 +- types/react-transition-group/Transition.d.ts | 2 +- types/react-transition-group/TransitionGroup.d.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/types/react-transition-group/CSSTransition.d.ts b/types/react-transition-group/CSSTransition.d.ts index 763ea80a0f..67b869edf6 100644 --- a/types/react-transition-group/CSSTransition.d.ts +++ b/types/react-transition-group/CSSTransition.d.ts @@ -33,6 +33,6 @@ export interface CSSTransitionProps extends TransitionProps { classNames: string | CSSTransitionClassNames; } -declare class CSSTransition extends Component {} +declare class CSSTransition extends Component {} export default CSSTransition; diff --git a/types/react-transition-group/Transition.d.ts b/types/react-transition-group/Transition.d.ts index 844561333c..24f0265ee2 100644 --- a/types/react-transition-group/Transition.d.ts +++ b/types/react-transition-group/Transition.d.ts @@ -66,6 +66,6 @@ export interface TransitionProps extends TransitionActions { * ``` * */ -declare class Transition extends Component {} +declare class Transition extends Component {} export default Transition; diff --git a/types/react-transition-group/TransitionGroup.d.ts b/types/react-transition-group/TransitionGroup.d.ts index e746d3ca77..3f04332bc8 100644 --- a/types/react-transition-group/TransitionGroup.d.ts +++ b/types/react-transition-group/TransitionGroup.d.ts @@ -1,4 +1,4 @@ -import { Component, HTMLProps, ReactElement, ReactType } from "react"; +import { Component, ReactType, HTMLProps, ReactElement } from "react"; import { TransitionActions, TransitionProps } from "react-transition-group/Transition"; export interface IntrinsicTransitionGroupProps extends TransitionActions { @@ -71,6 +71,6 @@ export type TransitionGroupProps {} +declare class TransitionGroup extends Component {} export default TransitionGroup;