diff --git a/types/i18next/index.d.ts b/types/i18next/index.d.ts index 958bff12a6..0eb8d64859 100644 --- a/types/i18next/index.d.ts +++ b/types/i18next/index.d.ts @@ -49,6 +49,8 @@ declare namespace i18n { joinArrays?: string; postProcess?: string | any[]; interpolation?: InterpolationOptions; + //add an indexer to assure that interpolation arguments can be passed + [x: string]: any; } interface Options { @@ -106,7 +108,7 @@ declare namespace i18n { t(key: string, options?: TranslationOptions): string | any | Array; - exists(): boolean; + exists(key, options?: TranslationOptions): boolean; setDefaultNamespace(ns: string): void; diff --git a/types/qhistory/index.d.ts b/types/qhistory/index.d.ts new file mode 100644 index 0000000000..301f6b4391 --- /dev/null +++ b/types/qhistory/index.d.ts @@ -0,0 +1,30 @@ +// Type definitions for qhistory 1.0 +// Project: https://github.com/pshrmn/qhistory#readme +// Definitions by: Diogo Franco +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +export as namespace qhistory; + +import { History } from 'history'; + +// augments the 'history' types when used +declare module 'history' { + interface Location { + // actually a complicated nested object/array system, but giving it a type + // makes _actually_ using it (or even casting to a known structure) much harder. + query: any; + } + + interface LocationDescriptorObject { + query?: object; + } +} + +declare function qhistory( + history: History, + stringify: (query: object) => string, + parse: (search: string) => object +): History; + +export default qhistory; diff --git a/types/qhistory/qhistory-tests.ts b/types/qhistory/qhistory-tests.ts new file mode 100644 index 0000000000..778e540beb --- /dev/null +++ b/types/qhistory/qhistory-tests.ts @@ -0,0 +1,19 @@ +import qhistory from 'qhistory'; +import { createBrowserHistory } from 'history'; +import * as qs from 'qs'; + +const history = qhistory(createBrowserHistory(), qs.stringify, qs.parse); + +history.listen(location => { + const query: { foo?: string } = location.query; + if (query.foo) { + const foo: string = query.foo; + } +}); + +history.push({ + pathname: '/', + query: { + foo: 'bar' + } +}); diff --git a/types/qhistory/tsconfig.json b/types/qhistory/tsconfig.json new file mode 100644 index 0000000000..e559937ec7 --- /dev/null +++ b/types/qhistory/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "dom", + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "qhistory-tests.ts" + ] +} diff --git a/types/qhistory/tslint.json b/types/qhistory/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/qhistory/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }