From 8ce79c9816ea9109d2460178c34c762e176a33a9 Mon Sep 17 00:00:00 2001 From: Logan Dam Date: Mon, 14 Jan 2019 17:31:36 +0200 Subject: [PATCH 1/2] added types for country-data --- types/country-data/country-data-tests.ts | 14 +++ types/country-data/index.d.ts | 103 +++++++++++++++++++++++ types/country-data/tsconfig.json | 23 +++++ types/country-data/tslint.json | 1 + 4 files changed, 141 insertions(+) create mode 100644 types/country-data/country-data-tests.ts create mode 100644 types/country-data/index.d.ts create mode 100644 types/country-data/tsconfig.json create mode 100644 types/country-data/tslint.json diff --git a/types/country-data/country-data-tests.ts b/types/country-data/country-data-tests.ts new file mode 100644 index 0000000000..e3b1ba663d --- /dev/null +++ b/types/country-data/country-data-tests.ts @@ -0,0 +1,14 @@ +import * as lib from 'country-data'; + +lib.callingCodes.all; // $ExpectType string[] +lib.callingCountries.all; // $ExpectType Country[] +lib.continents.africa; // $ExpectType Continent +lib.continents.africa.countries; // $ExpectType Country[] +lib.countries.all; // $ExpectType Country[] +lib.currencies.all; // $ExpectType Currency[] +lib.languages.all; // $ExpectType Language[] +lib.regions.antarctica; // $ExpectType Region +lib.regions.antarctica.countries; // $ExpectType string[] +lib.lookup.countries(""); // $ExpectType Country[] +lib.lookup.currencies(""); // $ExpectType Currency[] +lib.lookup.languages(""); // $ExpectType Language[] diff --git a/types/country-data/index.d.ts b/types/country-data/index.d.ts new file mode 100644 index 0000000000..4d97e3dc98 --- /dev/null +++ b/types/country-data/index.d.ts @@ -0,0 +1,103 @@ +// Type definitions for country-data 0.0 +// Project: https://github.com/OpenBookPrices/country-data +// Definitions by: Logan Dam +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export interface Country { + alpha2: string; + alpha3: string; + countryCallingCodes: string[]; + currencies: string[]; + emoji: string; + ioc: string; + languages: string[]; + name: string; + status: string; +} + +export interface Currency { + code: string; + decimals: number; + name: string; + number: number; +} + +export interface Language { + alpha2: string; + alpha3: string; + bibliographic: string; + name: string; +} + +export interface Continent { + name: string; + regions: string[]; + countries: Country[]; +} + +export interface Region { + name: string; + countries: string[]; +} + +export const countries: { + all: Country[]; +}; + +export const continents: { + africa: Continent; + antarctica: Continent; + asia: Continent; + europe: Continent; + northAmerica: Continent; + oceania: Continent; + southAmerica: Continent; +}; + +export const callingCodes: { + all: string[]; +}; + +export const callingCountries: { + all: Country[]; +}; + +export const currencies: { + all: Currency[]; +}; + +export const languages: { + all: Language[]; +}; + +export const regions: { + centralAsia: Region; + southernAsia: Region; + southeastAsia: Region; + eastAsia: Region; + westernAsia: Region; + centralAfrica: Region; + northAfrica: Region; + southernAfrica: Region; + eastAfrica: Region; + westAfrica: Region; + centralAmerica: Region; + northernAmerica: Region; + caribbean: Region; + southAmerica: Region; + antarctica: Region; + northernEurope: Region; + southernEurope: Region; + easternEurope: Region; + westernEurope: Region; + australia: Region; + melanesia: Region; + micronesia: Region; + polynesia: Region; +}; + +export const lookup: { + countries: (query: any) => Country[]; + currencies: (query: any) => Currency[]; + languages: (query: any) => Language[]; +}; diff --git a/types/country-data/tsconfig.json b/types/country-data/tsconfig.json new file mode 100644 index 0000000000..ccbbf6ecd6 --- /dev/null +++ b/types/country-data/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", + "country-data-tests.ts" + ] +} diff --git a/types/country-data/tslint.json b/types/country-data/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/country-data/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 46c5cdc2c2cfbd5663520f70ed221f217b07e35d Mon Sep 17 00:00:00 2001 From: Logan Dam Date: Mon, 14 Jan 2019 17:40:45 +0200 Subject: [PATCH 2/2] made things readonly --- types/country-data/country-data-tests.ts | 20 ++-- types/country-data/index.d.ts | 120 +++++++++++------------ 2 files changed, 70 insertions(+), 70 deletions(-) diff --git a/types/country-data/country-data-tests.ts b/types/country-data/country-data-tests.ts index e3b1ba663d..850116dc63 100644 --- a/types/country-data/country-data-tests.ts +++ b/types/country-data/country-data-tests.ts @@ -1,14 +1,14 @@ import * as lib from 'country-data'; -lib.callingCodes.all; // $ExpectType string[] -lib.callingCountries.all; // $ExpectType Country[] +lib.callingCodes.all; // $ExpectType ReadonlyArray +lib.callingCountries.all; // $ExpectType ReadonlyArray lib.continents.africa; // $ExpectType Continent -lib.continents.africa.countries; // $ExpectType Country[] -lib.countries.all; // $ExpectType Country[] -lib.currencies.all; // $ExpectType Currency[] -lib.languages.all; // $ExpectType Language[] +lib.continents.africa.countries; // $ExpectType ReadonlyArray +lib.countries.all; // $ExpectType ReadonlyArray +lib.currencies.all; // $ExpectType ReadonlyArray +lib.languages.all; // $ExpectType ReadonlyArray lib.regions.antarctica; // $ExpectType Region -lib.regions.antarctica.countries; // $ExpectType string[] -lib.lookup.countries(""); // $ExpectType Country[] -lib.lookup.currencies(""); // $ExpectType Currency[] -lib.lookup.languages(""); // $ExpectType Language[] +lib.regions.antarctica.countries; // $ExpectType ReadonlyArray +lib.lookup.countries(""); // $ExpectType ReadonlyArray +lib.lookup.currencies(""); // $ExpectType ReadonlyArray +lib.lookup.languages(""); // $ExpectType ReadonlyArray diff --git a/types/country-data/index.d.ts b/types/country-data/index.d.ts index 4d97e3dc98..80acbbcbba 100644 --- a/types/country-data/index.d.ts +++ b/types/country-data/index.d.ts @@ -4,100 +4,100 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped export interface Country { - alpha2: string; - alpha3: string; - countryCallingCodes: string[]; - currencies: string[]; - emoji: string; - ioc: string; - languages: string[]; - name: string; - status: string; + readonly alpha2: string; + readonly alpha3: string; + readonly countryCallingCodes: ReadonlyArray; + readonly currencies: ReadonlyArray; + readonly emoji: string; + readonly ioc: string; + readonly languages: ReadonlyArray; + readonly name: string; + readonly status: string; } export interface Currency { - code: string; - decimals: number; - name: string; - number: number; + readonly code: string; + readonly decimals: number; + readonly name: string; + readonly number: number; } export interface Language { - alpha2: string; - alpha3: string; - bibliographic: string; - name: string; + readonly alpha2: string; + readonly alpha3: string; + readonly bibliographic: string; + readonly name: string; } export interface Continent { - name: string; - regions: string[]; - countries: Country[]; + readonly name: string; + readonly regions: ReadonlyArray; + readonly countries: ReadonlyArray; } export interface Region { - name: string; - countries: string[]; + readonly name: string; + readonly countries: ReadonlyArray; } export const countries: { - all: Country[]; + readonly all: ReadonlyArray; }; export const continents: { - africa: Continent; - antarctica: Continent; - asia: Continent; - europe: Continent; - northAmerica: Continent; - oceania: Continent; - southAmerica: Continent; + readonly africa: Continent; + readonly antarctica: Continent; + readonly asia: Continent; + readonly europe: Continent; + readonly northAmerica: Continent; + readonly oceania: Continent; + readonly southAmerica: Continent; }; export const callingCodes: { - all: string[]; + readonly all: ReadonlyArray; }; export const callingCountries: { - all: Country[]; + readonly all: ReadonlyArray; }; export const currencies: { - all: Currency[]; + readonly all: ReadonlyArray; }; export const languages: { - all: Language[]; + readonly all: ReadonlyArray; }; export const regions: { - centralAsia: Region; - southernAsia: Region; - southeastAsia: Region; - eastAsia: Region; - westernAsia: Region; - centralAfrica: Region; - northAfrica: Region; - southernAfrica: Region; - eastAfrica: Region; - westAfrica: Region; - centralAmerica: Region; - northernAmerica: Region; - caribbean: Region; - southAmerica: Region; - antarctica: Region; - northernEurope: Region; - southernEurope: Region; - easternEurope: Region; - westernEurope: Region; - australia: Region; - melanesia: Region; - micronesia: Region; - polynesia: Region; + readonly centralAsia: Region; + readonly southernAsia: Region; + readonly southeastAsia: Region; + readonly eastAsia: Region; + readonly westernAsia: Region; + readonly centralAfrica: Region; + readonly northAfrica: Region; + readonly southernAfrica: Region; + readonly eastAfrica: Region; + readonly westAfrica: Region; + readonly centralAmerica: Region; + readonly northernAmerica: Region; + readonly caribbean: Region; + readonly southAmerica: Region; + readonly antarctica: Region; + readonly northernEurope: Region; + readonly southernEurope: Region; + readonly easternEurope: Region; + readonly westernEurope: Region; + readonly australia: Region; + readonly melanesia: Region; + readonly micronesia: Region; + readonly polynesia: Region; }; export const lookup: { - countries: (query: any) => Country[]; - currencies: (query: any) => Currency[]; - languages: (query: any) => Language[]; + readonly countries: (query: any) => ReadonlyArray; + readonly currencies: (query: any) => ReadonlyArray; + readonly languages: (query: any) => ReadonlyArray; };