From 13a7c4201358ca9cc3e8d39552f8be9acfe73fe5 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Mon, 9 Apr 2018 18:59:36 +0200 Subject: [PATCH] [react-native-i18n] Add type for react-native-i18n module (#24790) * Add type for react-native-i18n * Fix tests with correct typescript version --- types/react-native-i18n/index.d.ts | 11 +++++++++ .../react-native-i18n-tests.ts | 10 ++++++++ types/react-native-i18n/tsconfig.json | 23 +++++++++++++++++++ types/react-native-i18n/tslint.json | 1 + 4 files changed, 45 insertions(+) create mode 100644 types/react-native-i18n/index.d.ts create mode 100644 types/react-native-i18n/react-native-i18n-tests.ts create mode 100644 types/react-native-i18n/tsconfig.json create mode 100644 types/react-native-i18n/tslint.json diff --git a/types/react-native-i18n/index.d.ts b/types/react-native-i18n/index.d.ts new file mode 100644 index 0000000000..00d50e3caf --- /dev/null +++ b/types/react-native-i18n/index.d.ts @@ -0,0 +1,11 @@ +// Type definitions for react-native-i18n 2.0 +// Project: https://github.com/AlexanderZaytsev/react-native-i18n +// Definitions by: Vincent Langlet +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +import I18n = require("i18n-js"); + +export function getLanguages(): Promise; + +export default I18n; diff --git a/types/react-native-i18n/react-native-i18n-tests.ts b/types/react-native-i18n/react-native-i18n-tests.ts new file mode 100644 index 0000000000..1ab2134c69 --- /dev/null +++ b/types/react-native-i18n/react-native-i18n-tests.ts @@ -0,0 +1,10 @@ +import I18n, { getLanguages } from 'react-native-i18n'; + +getLanguages().then(languages => languages[0]); + +I18n.defaultLocale = 'en'; +I18n.fallbacks = true; +I18n.translations = {}; +I18n.locale = 'fr'; + +const currentLocale: string = I18n.currentLocale(); diff --git a/types/react-native-i18n/tsconfig.json b/types/react-native-i18n/tsconfig.json new file mode 100644 index 0000000000..f6a744565f --- /dev/null +++ b/types/react-native-i18n/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "react-native-i18n-tests.ts" + ] +} diff --git a/types/react-native-i18n/tslint.json b/types/react-native-i18n/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/react-native-i18n/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }