From 734ea84afcbb1ce7ad8b7668221f05bc3510770f Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Tue, 8 Aug 2017 22:50:03 +0200 Subject: [PATCH] [os-locale] add typings for v2, add strict null checks & linting (#18732) --- types/os-locale/index.d.ts | 18 +++++++++++------- types/os-locale/os-locale-tests.ts | 16 ++++++++-------- types/os-locale/tsconfig.json | 4 ++-- types/os-locale/tslint.json | 1 + types/os-locale/v1/index.d.ts | 14 ++++++++++++++ types/os-locale/v1/os-locale-tests.ts | 10 ++++++++++ types/os-locale/v1/tsconfig.json | 25 +++++++++++++++++++++++++ types/os-locale/v1/tslint.json | 1 + 8 files changed, 72 insertions(+), 17 deletions(-) create mode 100644 types/os-locale/tslint.json create mode 100644 types/os-locale/v1/index.d.ts create mode 100644 types/os-locale/v1/os-locale-tests.ts create mode 100644 types/os-locale/v1/tsconfig.json create mode 100644 types/os-locale/v1/tslint.json diff --git a/types/os-locale/index.d.ts b/types/os-locale/index.d.ts index c14e3b2bce..3a35e70766 100644 --- a/types/os-locale/index.d.ts +++ b/types/os-locale/index.d.ts @@ -1,13 +1,17 @@ -// Type definitions for os-locale 1.4.0 +// Type definitions for os-locale 2.1 // Project: https://github.com/sindresorhus/os-locale // Definitions by: Aya Morisawa +// BendingBender // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +export = osLocale; -declare function osLocale(options: { spawn?: boolean }, cb: (err: any, locale: string) => void): void; -declare function osLocale(cb: (err: any, locale: string) => void): void; -declare function osLocaleSync(): string; -declare function osLocaleSync(options: { spawn?: boolean }): string; +declare function osLocale(options?: osLocale.Options): Promise; -export { osLocaleSync as sync }; -export default osLocale; +declare namespace osLocale { + function sync(options?: Options): string; + + interface Options { + spawn?: boolean; + } +} diff --git a/types/os-locale/os-locale-tests.ts b/types/os-locale/os-locale-tests.ts index c54f45f6a0..233d9b5905 100644 --- a/types/os-locale/os-locale-tests.ts +++ b/types/os-locale/os-locale-tests.ts @@ -1,11 +1,11 @@ +import osLocale = require('os-locale'); -import osLocale, { sync } from 'os-locale'; - -osLocale((err: any, locale: string) => { +osLocale().then(locale => { + const str: string = locale; +}); +osLocale({spawn: false}).then(locale => { + const str: string = locale; }); -osLocale({spawn: false}, (err: any, locale: string) => { -}); - -var locale1: string = sync(); -var locale2: string = sync({spawn: false}); +const locale1: string = osLocale.sync(); +const locale2: string = osLocale.sync({spawn: false}); diff --git a/types/os-locale/tsconfig.json b/types/os-locale/tsconfig.json index 4cf5682e02..1ee35717ce 100644 --- a/types/os-locale/tsconfig.json +++ b/types/os-locale/tsconfig.json @@ -6,7 +6,7 @@ ], "noImplicitAny": true, "noImplicitThis": true, - "strictNullChecks": false, + "strictNullChecks": true, "baseUrl": "../", "typeRoots": [ "../" @@ -19,4 +19,4 @@ "index.d.ts", "os-locale-tests.ts" ] -} \ No newline at end of file +} diff --git a/types/os-locale/tslint.json b/types/os-locale/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/os-locale/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/os-locale/v1/index.d.ts b/types/os-locale/v1/index.d.ts new file mode 100644 index 0000000000..2861e64d6b --- /dev/null +++ b/types/os-locale/v1/index.d.ts @@ -0,0 +1,14 @@ +// Type definitions for os-locale 1.4 +// Project: https://github.com/sindresorhus/os-locale +// Definitions by: Aya Morisawa +// BendingBender +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export = osLocale; + +declare function osLocale(options: { spawn?: boolean }, cb: (err: any, locale: string) => void): void; +declare function osLocale(cb: (err: any, locale: string) => void): void; + +declare namespace osLocale { + function sync(options?: { spawn?: boolean }): string; +} diff --git a/types/os-locale/v1/os-locale-tests.ts b/types/os-locale/v1/os-locale-tests.ts new file mode 100644 index 0000000000..46e7c39b32 --- /dev/null +++ b/types/os-locale/v1/os-locale-tests.ts @@ -0,0 +1,10 @@ +import osLocale = require('os-locale'); + +osLocale((err: any, locale: string) => { +}); + +osLocale({spawn: false}, (err: any, locale: string) => { +}); + +const locale1: string = osLocale.sync(); +const locale2: string = osLocale.sync({spawn: false}); diff --git a/types/os-locale/v1/tsconfig.json b/types/os-locale/v1/tsconfig.json new file mode 100644 index 0000000000..833b306fa5 --- /dev/null +++ b/types/os-locale/v1/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../../", + "typeRoots": [ + "../../" + ], + "paths": { + "os-locale": ["os-locale/v1"] + }, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "os-locale-tests.ts" + ] +} diff --git a/types/os-locale/v1/tslint.json b/types/os-locale/v1/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/os-locale/v1/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }