Skip to content

Commit

Permalink
Simpler typescript types (#130)
Browse files Browse the repository at this point in the history
* Remove json from tsconfig

* just explicitly say type in typescript typings
  • Loading branch information
osdiab authored and xcarpentier committed Jul 4, 2018
1 parent 4304600 commit d7f1140
Show file tree
Hide file tree
Showing 2 changed files with 279 additions and 13 deletions.
287 changes: 278 additions & 9 deletions src/CountryPicker.d.ts
@@ -1,29 +1,298 @@
import { StyleProp, ViewStyle, ImageProps } from 'react-native';
import * as React from 'react';
import countries from '../data/countries.json';

/**
* Country metadata stored in this library to display and query `<CountryPicker
* />`
* Country metadata stored in this library to display and query
* `<CountryPicker />`
*/
export type Country = (typeof countries)[CCA2Code];
export interface Country {
currency: CurrencyCode;
callingCode: CallingCode;
flag: string;
name: { [key in TranslationLanguageCode]: string };
}

/**
* Country code, as specified in ISO 3166-1 alpha-2 (ie. `FR`, `US`, etc.)
*/
export type CCA2Code = keyof typeof countries;
export type CCA2Code =
| 'AF'
| 'AL'
| 'DZ'
| 'AS'
| 'AD'
| 'AO'
| 'AI'
| 'AQ'
| 'AG'
| 'AR'
| 'AM'
| 'AW'
| 'AU'
| 'AT'
| 'AZ'
| 'BS'
| 'BH'
| 'BD'
| 'BB'
| 'BY'
| 'BE'
| 'BZ'
| 'BJ'
| 'BM'
| 'BT'
| 'BO'
| 'BA'
| 'BW'
| 'BV'
| 'BR'
| 'IO'
| 'VG'
| 'BN'
| 'BG'
| 'BF'
| 'BI'
| 'KH'
| 'CM'
| 'CA'
| 'CV'
| 'KY'
| 'CF'
| 'TD'
| 'CL'
| 'CN'
| 'CX'
| 'CC'
| 'CO'
| 'KM'
| 'CK'
| 'CR'
| 'HR'
| 'CU'
| 'CW'
| 'CY'
| 'CZ'
| 'CD'
| 'DK'
| 'DJ'
| 'DM'
| 'DO'
| 'EC'
| 'EG'
| 'SV'
| 'GQ'
| 'ER'
| 'EE'
| 'ET'
| 'FK'
| 'FO'
| 'FJ'
| 'FI'
| 'FR'
| 'GF'
| 'PF'
| 'TF'
| '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'TK'
| 'TO'
| 'TT'
| 'TN'
| 'TR'
| 'TM'
| 'TC'
| 'TV'
| 'UG'
| 'UA'
| 'AE'
| 'GB'
| 'US'
| 'UM'
| 'VI'
| 'UY'
| 'UZ'
| 'VU'
| 'VA'
| 'VE'
| 'VN'
| 'WF'
| 'EH'
| 'YE'
| 'ZM'
| 'ZW'
| 'AX';
/**
* Calling code for a given country. For example: `United States (+1)`
* Calling code for a given country. For example, the entry for United States is
* `1` (referring to "+1`")
*/
export type CallingCode = string;
/**
* Currency code for a country, as specified in ISO 4217. For example, US
* Dollars are `USD`
* Currency code for a country, as specified in ISO 4217. For example, the entry
* for United States is `USD` (referring to US Dollars)
*/
export type CurrencyCode = string;
/**
* Language codes for available translations in this library
*/
export type TranslationLanguageCode = keyof Country['name'];
export type TranslationLanguageCode =
| 'common'
| 'cym'
| 'deu'
| 'fra'
| 'hrv'
| 'ita'
| 'jpn'
| 'nld'
| 'por'
| 'rus'
| 'spa'
| 'svk'
| 'fin'
| 'zho'
| 'isr';

export enum FlagType {
FLAT = 'flat',
Expand Down
5 changes: 1 addition & 4 deletions tsconfig.json
Expand Up @@ -15,9 +15,6 @@
/* Additional Checks */
"noUnusedLocals": true /* Report errors on unused locals. */,
"noUnusedParameters": true /* Report errors on unused parameters. */,
"noImplicitReturns": true /* Report error when not all code paths in function return a value. */,

/* Module Resolution Options */
"resolveJsonModule": true /* Resolve JSON modules to get types from JSON source data*/
"noImplicitReturns": true /* Report error when not all code paths in function return a value. */
}
}

0 comments on commit d7f1140

Please sign in to comment.