From 65a214f765f1ffb8cc282012f00e59d5218ae2e2 Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Sun, 9 Dec 2018 16:08:47 +0100 Subject: [PATCH] Add types for coinlist --- types/coinlist/coinlist-tests.ts | 36 ++++++++++++++++++++++++++++++ types/coinlist/index.d.ts | 19 ++++++++++++++++ types/coinlist/src/coins.json.d.ts | 11 +++++++++ types/coinlist/tsconfig.json | 24 ++++++++++++++++++++ types/coinlist/tslint.json | 1 + 5 files changed, 91 insertions(+) create mode 100644 types/coinlist/coinlist-tests.ts create mode 100644 types/coinlist/index.d.ts create mode 100644 types/coinlist/src/coins.json.d.ts create mode 100644 types/coinlist/tsconfig.json create mode 100644 types/coinlist/tslint.json diff --git a/types/coinlist/coinlist-tests.ts b/types/coinlist/coinlist-tests.ts new file mode 100644 index 0000000000..17dbbae3df --- /dev/null +++ b/types/coinlist/coinlist-tests.ts @@ -0,0 +1,36 @@ +import coins = require('coinlist'); +import coinsJson = require('coinlist/src/coins.json'); + +// $ExpectType Coin[] & CoinsAPI +coins; + +// $ExpectType Coin[] +coinsJson; + +let coinsArr = [ + { + id: 'bitcoin', + symbol: 'BTC', + name: 'Bitcoin', + }, + { + id: 'litecoin', + symbol: 'LTC', + name: 'Litecoin', + }, +]; + +coinsArr = coins; +coinsArr = coinsJson; + +// $ExpectType Coin | undefined +coins.get('BTC'); + +// $ExpectType string | undefined +coins.get('BTC', 'name'); +// $ExpectType string | undefined +coins.get('BTC', 'symbol'); +// $ExpectType string | undefined +coins.get('BTC', 'id'); + +coins.map(coin => coin.name); diff --git a/types/coinlist/index.d.ts b/types/coinlist/index.d.ts new file mode 100644 index 0000000000..29aaa1dcaa --- /dev/null +++ b/types/coinlist/index.d.ts @@ -0,0 +1,19 @@ +// Type definitions for coinlist 3.1 +// Project: https://github.com/lukechilds/coinlist +// Definitions by: BendingBender +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import coinsJson = require('./src/coins.json'); + +export = coins; + +declare const coins: coins.Coin[] & coins.CoinsAPI; + +declare namespace coins { + type Coin = coinsJson.Coin; + + interface CoinsAPI { + get(symbol: string): Coin | undefined; + get(symbol: string, property: 'id' | 'symbol' | 'name'): string | undefined; + } +} diff --git a/types/coinlist/src/coins.json.d.ts b/types/coinlist/src/coins.json.d.ts new file mode 100644 index 0000000000..96c947bd8a --- /dev/null +++ b/types/coinlist/src/coins.json.d.ts @@ -0,0 +1,11 @@ +export = coins; + +declare const coins: coins.Coin[]; + +declare namespace coins { + interface Coin { + id: string; + symbol: string; + name: string; + } +} diff --git a/types/coinlist/tsconfig.json b/types/coinlist/tsconfig.json new file mode 100644 index 0000000000..86b93f8380 --- /dev/null +++ b/types/coinlist/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "src/coins.json.d.ts", + "coinlist-tests.ts" + ] +} diff --git a/types/coinlist/tslint.json b/types/coinlist/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/coinlist/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }