From 118178afb42498e21fa8ed7f41bbb8a6bfc8b56b Mon Sep 17 00:00:00 2001 From: chatoo2412 Date: Thu, 24 Jan 2019 14:26:47 +0900 Subject: [PATCH] [accept-language-parser] introduce generic --- .../accept-language-parser-tests.ts | 6 ++++++ types/accept-language-parser/index.d.ts | 9 +++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/types/accept-language-parser/accept-language-parser-tests.ts b/types/accept-language-parser/accept-language-parser-tests.ts index 586a31cb93..6f308b5315 100644 --- a/types/accept-language-parser/accept-language-parser-tests.ts +++ b/types/accept-language-parser/accept-language-parser-tests.ts @@ -20,11 +20,17 @@ const l3: AcceptLanguageParser.Language = { quality: 0.9 }; +type Lang = "en-US" | "ko-KR"; +const enUs: Lang = "en-US"; +const koKr: Lang = "ko-KR"; + const parsed1: AcceptLanguageParser.Language[] = AcceptLanguageParser.parse(''); const pick1: string | null = AcceptLanguageParser.pick([''], ''); const pick2: string | null = AcceptLanguageParser.pick([''], [l1, l2, l3]); const pick3: string | null = AcceptLanguageParser.pick([''], '', {}); const pick4: string | null = AcceptLanguageParser.pick([''], '', { loose: true }); +const pick5: Lang | null = AcceptLanguageParser.pick([enUs, koKr], [l1, l2, l3]); +const pick6: Lang | null = AcceptLanguageParser.pick([enUs, koKr], [l1, l2, l3]); const pickOptions: AcceptLanguageParser.PickOptions = { loose: true diff --git a/types/accept-language-parser/index.d.ts b/types/accept-language-parser/index.d.ts index c47969c940..4bec11b89c 100644 --- a/types/accept-language-parser/index.d.ts +++ b/types/accept-language-parser/index.d.ts @@ -1,17 +1,18 @@ // Type definitions for accept-language-parser 1.5 // Project: https://github.com/opentable/accept-language-parser // Definitions by: Niklas Wulf +// Wooram Jun // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.1 -// https://github.com/opentable/accept-language-parser/blob/v1.4.1/index.js +// https://github.com/opentable/accept-language-parser/blob/v1.5.0/index.js export function parse(acceptLanguage: string): Language[]; -export function pick( - supportedLanguages: string[], +export function pick( + supportedLanguages: T[], acceptLanguage: string | Language[], options?: PickOptions -): string | null; +): T | null; export interface Language { code: string;