From b178a98ffd261b1bcc0c7c220ab8bc46b3f44cf8 Mon Sep 17 00:00:00 2001 From: Dave Cardwell Date: Wed, 24 Oct 2018 20:53:02 -0400 Subject: [PATCH 1/2] [browserslist] Add initial types for browserslist --- types/browserslist/browserslist-tests.ts | 22 ++++++++++++++++ types/browserslist/index.d.ts | 33 ++++++++++++++++++++++++ types/browserslist/tsconfig.json | 16 ++++++++++++ types/browserslist/tslint.json | 1 + 4 files changed, 72 insertions(+) create mode 100644 types/browserslist/browserslist-tests.ts create mode 100644 types/browserslist/index.d.ts create mode 100644 types/browserslist/tsconfig.json create mode 100644 types/browserslist/tslint.json diff --git a/types/browserslist/browserslist-tests.ts b/types/browserslist/browserslist-tests.ts new file mode 100644 index 0000000000..d5e88e5b5d --- /dev/null +++ b/types/browserslist/browserslist-tests.ts @@ -0,0 +1,22 @@ +import browserslist from "browserslist"; + +browserslist(); // $ExpectType string[] +browserslist(""); // $ExpectType string[] +browserslist([""]); // $ExpectType string[] + +const opts: browserslist.Options[] = [ + {}, + { path: "" }, + { env: "" }, + { stats: { "": { "": 0 } } }, + { config: "" }, + { ignoreUnknownVersions: false }, + { dangerousExtend: false } +]; +for (const opt of opts) { + browserslist("", opt); // $ExpectType string[] + browserslist([""], opt); // $ExpectType string[] +} + +browserslist.coverage([""]); // $ExpectType number +browserslist.coverage([""], { "": { "": 0 } }); // $ExpectType number diff --git a/types/browserslist/index.d.ts b/types/browserslist/index.d.ts new file mode 100644 index 0000000000..6edcb47ab4 --- /dev/null +++ b/types/browserslist/index.d.ts @@ -0,0 +1,33 @@ +// Type definitions for browserslist 4.3 +// Project: https://github.com/browserslist/browserslist#readme +// Definitions by: Dave Cardwell +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare namespace browserslist { + interface Browserslist { + (queries?: string | ReadonlyArray, opts?: Options): string[]; + + coverage: (browsers: ReadonlyArray, stats?: Stats) => number; + + clearCaches: () => void; + } + + interface Stats { + [browser: string]: { + [version: string]: number; + }; + } + + interface Options { + path?: string; + env?: string; + stats?: Stats; + config?: string; + ignoreUnknownVersions?: boolean; + dangerousExtend?: boolean; + } +} + +declare var browserslist: browserslist.Browserslist; + +export default browserslist; diff --git a/types/browserslist/tsconfig.json b/types/browserslist/tsconfig.json new file mode 100644 index 0000000000..11138a612f --- /dev/null +++ b/types/browserslist/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": ["index.d.ts", "browserslist-tests.ts"] +} diff --git a/types/browserslist/tslint.json b/types/browserslist/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/browserslist/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 4bcadac46916c00d9463d155563e890b56a93214 Mon Sep 17 00:00:00 2001 From: Dave Cardwell Date: Thu, 8 Nov 2018 12:55:17 -0500 Subject: [PATCH 2/2] [browserslist] Switch to `export =` --- types/browserslist/index.d.ts | 3 ++- types/browserslist/tsconfig.json | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/types/browserslist/index.d.ts b/types/browserslist/index.d.ts index 6edcb47ab4..7c4a0add0c 100644 --- a/types/browserslist/index.d.ts +++ b/types/browserslist/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/browserslist/browserslist#readme // Definitions by: Dave Cardwell // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.7 declare namespace browserslist { interface Browserslist { @@ -30,4 +31,4 @@ declare namespace browserslist { declare var browserslist: browserslist.Browserslist; -export default browserslist; +export = browserslist; diff --git a/types/browserslist/tsconfig.json b/types/browserslist/tsconfig.json index 11138a612f..cf68d8bf64 100644 --- a/types/browserslist/tsconfig.json +++ b/types/browserslist/tsconfig.json @@ -10,7 +10,8 @@ "typeRoots": ["../"], "types": [], "noEmit": true, - "forceConsistentCasingInFileNames": true + "forceConsistentCasingInFileNames": true, + "esModuleInterop": true }, "files": ["index.d.ts", "browserslist-tests.ts"] }