diff --git a/types/draft-js/index.d.ts b/types/draft-js/index.d.ts index a79de31e70..c0086319a3 100644 --- a/types/draft-js/index.d.ts +++ b/types/draft-js/index.d.ts @@ -9,7 +9,7 @@ import * as Immutable from 'immutable'; type SyntheticKeyboardEvent = React.KeyboardEvent<{}>; type SyntheticEvent = React.SyntheticEvent<{}>; - +export as namespace Draft; declare namespace Draft { namespace Component { namespace Base { diff --git a/types/electron-settings/electron-settings-tests.ts b/types/electron-settings/electron-settings-tests.ts new file mode 100644 index 0000000000..a1fad17f10 --- /dev/null +++ b/types/electron-settings/electron-settings-tests.ts @@ -0,0 +1,26 @@ +import settings = require("electron-settings"); + +settings.has('foo.bar'); // $ExpectType boolean + +settings.set('foo.bar', 'test'); // $ExpectType Settings +settings.set('foo.bar', 'test', {prettify: true}); // $ExpectType Settings +settings.set('foo.bar', {test: 'test'}); // $ExpectType Settings +settings.set('foo.bar', {test: 'test'}, {prettify: true}); // $ExpectType Settings + +settings.setAll({foo: {bar: 'test'}}); // $ExpectType Settings +settings.setAll({foo: {bar: 'test'}}, {prettify: true}); // $ExpectType Settings + +settings.get('foo.bar'); // $ExpectType JsonValue +settings.get('foo.bar', 'test'); // $ExpectType JsonValue + +settings.getAll(); // $ExpectType JsonValue + +settings.delete('foo.bar'); // $ExpectType Settings +settings.delete('foo.bar', {prettify: true}); // $ExpectType Settings + +settings.deleteAll(); // $ExpectType Settings +settings.deleteAll({prettify: true}); // $ExpectType Settings + +settings.watch('foo.bar', () => {}); // $ExpectType SettingsObserver + +settings.file(); // $ExpectType string diff --git a/types/electron-settings/index.d.ts b/types/electron-settings/index.d.ts new file mode 100644 index 0000000000..21bc1fb446 --- /dev/null +++ b/types/electron-settings/index.d.ts @@ -0,0 +1,122 @@ +// Type definitions for electron-settings 3.0 +// Project: https://github.com/nathanbuchar/electron-settings#readme +// Definitions by: Ian Copp +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +import * as fs from "fs"; + +type SettingsHandler = (newValue: any, oldValue: any) => any; + +interface JsonObject { + [x: string]: JsonValue; +} + +interface JsonArray extends Array {} // tslint:disable-line no-empty-interface + +type JsonValue = string | number | boolean | null | JsonArray | JsonObject; + +interface SettingsOptions { + /** + * Prettify the JSON output. Defaults to `false`. + */ + prettify?: boolean; +} + +interface Settings extends NodeJS.EventEmitter { + /** + * Returns a boolean indicating whether the settings object contains the + * given key path. + */ + has(keyPath: string): boolean; + + /** + * Sets the value at the given key path and returns the Settings instance. + * Chainable. + * @param keyPath The path to the key whose value we wish to set. This key + * need not already exist. + * @param value The value to set the key at the chosen key path to. This + * must be a data type supported by JSON. + * @see #setAll + */ + set(keyPath: string, value: JsonValue, options?: SettingsOptions): Settings; + + /** + * Sets all settings and returns the Settings instance. Chainable. + * @param obj The new settings object. + * @see #set + */ + setAll(obj: JsonValue, options?: SettingsOptions): Settings; + + /** + * Returns the value at the given key path, or sets the value at that key + * path to the default value, if provided, if the key does not exist. + * @param defaultValue The value to apply if the setting does not already + * exist. + * @see #getAll + */ + get(keyPath: string, defaultValue?: any): JsonValue; + + /** + * Returns all settings. + * @see #get + */ + getAll(): JsonValue; + + /** + * Deletes the key and value at the given key path and returns the Settings + * instance. Chainable. + * @see #deleteAll + */ + delete(keyPath: string, options?: SettingsOptions): Settings; + + /** + * Deletes all settings and returns the Settings instance. Chainable. + * @see #delete + */ + deleteAll(options?: SettingsOptions): Settings; + + /** + * Returns an Observer instance which watches the given key path for changes + * and calls the given handler if the value changes. To unsubscribe from + * changes, call observer.dispose(). + * @param keyPath The path to the key that we wish to watch for changes. + * @param handler The callback that will be invoked if the value at the + * chosen key path changes. The context of this callback is + * that of the observer instance. + */ + watch(keyPath: string, handler: SettingsHandler): SettingsObserver; + + /** + * Returns the absolute path to where the settings file is or will be + * stored. + * + * In general, the settings file is stored in your app's user data directory + * in a file called Settings. The default user data directory for your + * system can be found below. + * + * * MacOS: If you're running macOS, your app's default user data directory + * is `~/Library/Application\ Support/`. + * * Windows: If you're running Windows, your app's default user data + * directory is `%APPDATA%/`. + * * Linux: If you're running Linux, your app's default user data directory + * is either `$XDG_CONFIG_HOME/` or `~/.config/`. + * + * If you wish, you may change your app's default user data directory by + * calling Electron's `app.setPath()` method before the ready event of the + * app module is emitted, but this is not recommended, as it will likely + * cause unintended consequences. + */ + file(): string; +} + +interface SettingsObserver { + /** + * Disposes of this Observer instance. + */ + dispose(): void; +} + +declare var settings: Settings; +export = settings; diff --git a/types/electron-settings/tsconfig.json b/types/electron-settings/tsconfig.json new file mode 100644 index 0000000000..a9a5a70afc --- /dev/null +++ b/types/electron-settings/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "electron-settings-tests.ts" + ] +} diff --git a/types/electron-settings/tslint.json b/types/electron-settings/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/electron-settings/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/karma-chai/index.d.ts b/types/karma-chai/index.d.ts new file mode 100644 index 0000000000..87910cb6e2 --- /dev/null +++ b/types/karma-chai/index.d.ts @@ -0,0 +1,12 @@ +// Type definitions for karma-chai 0.1 +// Project: http://xdissent.github.io/karma-chai +// Definitions by: Jay Sherby +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import chai = require('chai'); + +declare global { + var assert: Chai.AssertStatic; + var expect: Chai.ExpectStatic; + var should: Chai.Should; +} diff --git a/types/karma-chai/karma-chai-tests.ts b/types/karma-chai/karma-chai-tests.ts new file mode 100644 index 0000000000..d463dc6371 --- /dev/null +++ b/types/karma-chai/karma-chai-tests.ts @@ -0,0 +1,3 @@ +true.should.be.ok; +expect(true).to.be.ok; +assert.isTrue(true); diff --git a/types/karma-chai/tsconfig.json b/types/karma-chai/tsconfig.json new file mode 100644 index 0000000000..578bca4c14 --- /dev/null +++ b/types/karma-chai/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "karma-chai-tests.ts" + ] +} diff --git a/types/karma-chai/tslint.json b/types/karma-chai/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/karma-chai/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/mapbox/index.d.ts b/types/mapbox/index.d.ts index 87a34e4823..2fe8de9eaf 100644 --- a/types/mapbox/index.d.ts +++ b/types/mapbox/index.d.ts @@ -14,7 +14,7 @@ declare global { // Map ////////////////////////////////////////////////////////////////////// - const accessToken: string; + let accessToken: string; /** * Create and automatically configure a map with layers, markers, and interactivity. diff --git a/types/mapbox/mapbox-tests.ts b/types/mapbox/mapbox-tests.ts index f81a7b432e..f4d0750199 100644 --- a/types/mapbox/mapbox-tests.ts +++ b/types/mapbox/mapbox-tests.ts @@ -37,3 +37,6 @@ const marker2 = L.mapbox.featureLayer({ marker2.eachLayer((marker: L.Marker) => { marker.openPopup(); }); + +// Can set the API key via left hand assignment +L.mapbox.accessToken = "keyGoesHere"; diff --git a/types/sharepoint/index.d.ts b/types/sharepoint/index.d.ts index 4e6167ad53..3520e12f06 100644 --- a/types/sharepoint/index.d.ts +++ b/types/sharepoint/index.d.ts @@ -1,5 +1,5 @@ -// Type definitions for SharePoint: 2010.1 / 2013.1 -// Project: https:// github.com/gandjustas/sptypescript +// Type definitions for Microsoft SharePoint: 2013.1 +// Project: https://msdn.microsoft.com/en-us/library/office/jj193034.aspx // Definitions by: Stanislav Vyshchepan , Andrey Markeev // Definitions: https:// github.com/DefinitelyTyped/DefinitelyTyped diff --git a/types/sinon/index.d.ts b/types/sinon/index.d.ts index 4a02ec691a..7907d4a7ff 100644 --- a/types/sinon/index.d.ts +++ b/types/sinon/index.d.ts @@ -79,6 +79,7 @@ declare namespace Sinon { alwaysReturned(obj: any): boolean; invokeCallback(...args: any[]): void; getCall(n: number): SinonSpyCall; + getCalls(): SinonSpyCall[]; reset(): void; printf(format: string, ...args: any[]): string; restore(): void; @@ -260,6 +261,8 @@ declare namespace Sinon { setResponseBody(body: string): void; respond(status: number, headers: any, body: string): void; autoRespond(ms: number): void; + error(): void; + onerror(): void; } interface SinonFakeXMLHttpRequestStatic { diff --git a/types/sinon/sinon-tests.ts b/types/sinon/sinon-tests.ts index 2637d92c33..404cf1ef39 100644 --- a/types/sinon/sinon-tests.ts +++ b/types/sinon/sinon-tests.ts @@ -147,3 +147,11 @@ class TestCreateStubInstance { } sinon.createStubInstance(TestCreateStubInstance).someTestMethod('some argument'); + +function testGetCalls() { + var double = sinon.spy((a: number) => a * 2); + double(2); + double(4); + double.getCall(0).args.length === 1; + double.getCalls().find(call => call.args[0] === 4).returnValue === 8; +} \ No newline at end of file diff --git a/types/vue-i18n/index.d.ts b/types/vue-i18n/index.d.ts new file mode 100644 index 0000000000..02174cb784 --- /dev/null +++ b/types/vue-i18n/index.d.ts @@ -0,0 +1,79 @@ +// Type definitions for vue-i18n 6.1 +// Project: https://github.com/kazupon/vue-i18n +// Definitions by: Kombu +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import * as Vue from 'vue'; +import { PluginFunction } from 'vue'; + +declare namespace VueI18n { + type Path = string; + type Locale = string; + type Values = any[] | { [key: string]: any }; + type Choice = number; + type LocaleMessage = string | LocaleMessageObject | LocaleMessageArray; + interface LocaleMessageObject { [key: string]: LocaleMessage; } + interface LocaleMessageArray { [index: number]: LocaleMessage; } + interface LocaleMessages { [key: string]: LocaleMessageObject; } + type TranslateResult = string | LocaleMessageArray; + + interface Formatter { + format(message: string, values: Values): string; + } + + type MissingHandler = (locale: Locale, key: Path, vm?: Vue) => void; + + // tslint:disable-next-line:interface-name + interface I18nOptions { + locale?: Locale; + fallbackLocale?: Locale; + messages?: LocaleMessages; + formatter?: Formatter; + missing?: MissingHandler; + fallbackRoot?: boolean; + sync?: boolean; + silentTranslationWarn?: boolean; + } +} + +declare class VueI18n { + constructor(options?: VueI18n.I18nOptions) + + readonly messages: VueI18n.LocaleMessages; + + locale: VueI18n.Locale; + fallbackLocale: VueI18n.Locale; + missing: VueI18n.MissingHandler; + formatter: VueI18n.Formatter; + silentTranslationWarn: boolean; + + t(key: VueI18n.Path, values?: VueI18n.Values): VueI18n.TranslateResult; + t(key: VueI18n.Path, locale: VueI18n.Locale, values?: VueI18n.Values): VueI18n.TranslateResult; + tc(key: VueI18n.Path, choice?: VueI18n.Choice, values?: VueI18n.Values): string; + tc(key: VueI18n.Path, choice: VueI18n.Choice, locale: VueI18n.Locale, values?: VueI18n.Values): string; + te(key: VueI18n.Path, locale?: VueI18n.Locale): boolean; + + getLocaleMessage(locale: VueI18n.Locale): VueI18n.LocaleMessageObject; + setLocaleMessage(locale: VueI18n.Locale, message: VueI18n.LocaleMessageObject): void; + mergeLocaleMessage(locale: VueI18n.Locale, message: VueI18n.LocaleMessageObject): void; + + static install: PluginFunction; + static version: string; +} + +declare module 'vue/types/vue' { + interface Vue { + readonly $i18n: VueI18n; + $t: typeof VueI18n.prototype.t; + $tc: typeof VueI18n.prototype.tc; + $te: typeof VueI18n.prototype.te; + } +} + +declare module 'vue/types/options' { + interface ComponentOptions { + i18n?: VueI18n; + } +} + +export = VueI18n; diff --git a/types/vue-i18n/package.json b/types/vue-i18n/package.json new file mode 100644 index 0000000000..ca67af43b1 --- /dev/null +++ b/types/vue-i18n/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "vue": "^2.2.6" + } +} diff --git a/types/vue-i18n/tsconfig.json b/types/vue-i18n/tsconfig.json new file mode 100644 index 0000000000..cbff597b4f --- /dev/null +++ b/types/vue-i18n/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "vue-i18n-tests.ts" + ] +} diff --git a/types/vue-i18n/tslint.json b/types/vue-i18n/tslint.json new file mode 100644 index 0000000000..d88586e5bd --- /dev/null +++ b/types/vue-i18n/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} diff --git a/types/vue-i18n/vue-i18n-tests.ts b/types/vue-i18n/vue-i18n-tests.ts new file mode 100644 index 0000000000..7ff9dab6e1 --- /dev/null +++ b/types/vue-i18n/vue-i18n-tests.ts @@ -0,0 +1,99 @@ +/// + +const assert = console.assert; +const random = () => Math.trunc(Math.exp(Math.log(Date.now()) * Math.random())); + +import * as Vue from 'vue'; +import * as VueI18n from 'vue-i18n'; +import { ComponentOptions } from 'vue'; + +/** + * VueI18n.install + */ +Vue.use(VueI18n); +VueI18n.install(Vue); + +/** + * VueI18n.version + */ +assert(typeof VueI18n.version === 'string'); + +/** + * VueI18n Instance + */ +const locale = random().toString(); +const key = `_${random()}`; +const value = `${random()}|${random()}|${random()}`; +const i18n = new VueI18n({ + locale, + fallbackLocale: locale, + messages: { + [locale]: { + [key]: value, + }, + }, + formatter: { + format(message, values) { + return message; + }, + }, + missing(locale, key, vm) { + }, + fallbackRoot: false, + sync: true, + silentTranslationWarn: true, +}); +assert(i18n.messages[locale][key] === value); +assert(i18n.locale === locale); +assert(i18n.fallbackLocale === locale); +assert(typeof i18n.missing === 'function'); +assert(typeof i18n.formatter.format === 'function'); +assert(i18n.silentTranslationWarn); +i18n.setLocaleMessage(locale, {}); +assert(i18n.getLocaleMessage(locale)[key] === undefined); +i18n.mergeLocaleMessage(locale, { [key]: value }); +assert(i18n.getLocaleMessage(locale)[key] === value); +assert(typeof i18n.t === 'function'); +assert(typeof i18n.tc === 'function'); +assert(typeof i18n.te === 'function'); + +/** + * Vue + */ +const vm = new Vue({ + i18n, +}); +assert(vm.$i18n === i18n); +assert(vm.$t(key) === value); +assert(vm.$t(key, ['', 0, false, null, undefined]) === value); +assert(vm.$t(key, { x: 'x' }) === value); +assert(vm.$t(key, locale) === value); +assert(vm.$t(key, locale, ['', 0, false, null, undefined]) === value); +assert(vm.$t(key, locale, { x: 'x' }) === value); +assert(vm.$tc(key) === value); +assert(vm.$tc(key, 1) === value.split('|')[1]); +assert(vm.$tc(key, 1, []) === value.split('|')[1]); +assert(vm.$tc(key, 1, {}) === value.split('|')[1]); +assert(vm.$tc(key, 1, locale) === value.split('|')[1]); +assert(vm.$tc(key, 1, locale, []) === value.split('|')[1]); +assert(vm.$tc(key, 1, locale, {}) === value.split('|')[1]); +assert(vm.$te(key)); +assert(vm.$te(key, locale)); + +/** + * VueI18n + */ +{ + let path: VueI18n.Path; + let locale: VueI18n.Locale; + let values: VueI18n.Values; + let choice: VueI18n.Choice; + let localeMessage: VueI18n.LocaleMessage; + let localeMessageObject: VueI18n.LocaleMessageObject; + let localeMessageArray: VueI18n.LocaleMessageArray; + let localeMessages: VueI18n.LocaleMessages; + let translateResult: VueI18n.TranslateResult; + let formatter: VueI18n.Formatter; + let missingHandler: VueI18n.MissingHandler; + let i18nOptions: VueI18n.I18nOptions; +}