From 86e15b1d9d399b5ac2dddb3ac7e8458e8459aba6 Mon Sep 17 00:00:00 2001 From: Kamil Rojewski Date: Tue, 4 Apr 2017 14:19:40 +0200 Subject: [PATCH 0001/2144] Uint support --- types/flatbuffers/index.d.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/types/flatbuffers/index.d.ts b/types/flatbuffers/index.d.ts index e813ab461b..1342acdf15 100644 --- a/types/flatbuffers/index.d.ts +++ b/types/flatbuffers/index.d.ts @@ -498,24 +498,48 @@ declare namespace flatbuffers { */ writeInt8(offset: number, value: number): void; + /** + * @param {number} offset + * @param {number} value + */ + writeUint8(offset: number, value: number): void; + /** * @param {number} offset * @param {number} value */ writeInt16(offset: number, value: number): void; + /** + * @param {number} offset + * @param {number} value + */ + writeUint16(offset: number, value: number): void; + /** * @param {number} offset * @param {number} value */ writeInt32(offset: number, value: number): void; + /** + * @param {number} offset + * @param {number} value + */ + writeUint32(offset: number, value: number): void; + /** * @param {number} offset * @param {flatbuffers.Long} value */ writeInt64(offset: number, value: Long): void; + /** + * @param {number} offset + * @param {flatbuffers.Long} value + */ + writeUint64(offset: number, value: Long): void; + /** * @param {number} offset * @param {number} value From 8eca1512eb4c8fa3418d6355c8fbee2cecb69dc1 Mon Sep 17 00:00:00 2001 From: John McLaughlin Date: Wed, 2 Aug 2017 12:13:39 +0700 Subject: [PATCH 0002/2144] Fixed types of debug.names and debug.skips arrays. --- types/debug/debug-tests.ts | 1 + types/debug/index.d.ts | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/types/debug/debug-tests.ts b/types/debug/debug-tests.ts index fc8d3c5e56..73a16fe782 100644 --- a/types/debug/debug-tests.ts +++ b/types/debug/debug-tests.ts @@ -12,6 +12,7 @@ log("Formatted test (%d arg)", 1); log("Formatted %s (%d args)", "test", 2); log("Enabled?: %s", debug.enabled("DefinitelyTyped:log")); +log("Name Enabled: %s", debug.names.some(name => name.test("DefinitelyTyped:log"))); log("Namespace: %s", log.namespace); var error:debug.IDebugger = debug("DefinitelyTyped:error"); diff --git a/types/debug/index.d.ts b/types/debug/index.d.ts index 45d3ad02f3..8987b13a26 100644 --- a/types/debug/index.d.ts +++ b/types/debug/index.d.ts @@ -1,6 +1,8 @@ // Type definitions for debug // Project: https://github.com/visionmedia/debug -// Definitions by: Seon-Wook Park , Gal Talmor +// Definitions by: Seon-Wook Park +// Gal Talmor +// John McLaughlin // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare var debug: debug.IDebug; @@ -16,8 +18,8 @@ declare namespace debug { enable: (namespaces: string) => void, enabled: (namespaces: string) => boolean, - names: string[], - skips: string[], + names: RegExp[], + skips: RegExp[], formatters: IFormatters } From e5545e729bb7b6c76816800e9d39ccdd21b147fa Mon Sep 17 00:00:00 2001 From: "Andrew Stiegmann (stieg)" Date: Thu, 18 Jan 2018 15:56:13 -1000 Subject: [PATCH 0003/2144] Add `usePushEach` flag to Mongoose Schema Options In order for devs to be able to work around the issues described in https://github.com/Automattic/mongoose/issues/5574 we need to be able to supply the `usePushEach` flag to the Mongoose SchemaOptions. This options functionality is described in https://github.com/Automattic/mongoose/issues/4455 and is required for anyone who modifies arrays inline who is using Mongoose 4 and MongoDB 3.6+ Testing: Copied changes to local project and verified compilation worked. --- types/mongoose/index.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/types/mongoose/index.d.ts b/types/mongoose/index.d.ts index 3e676b499f..ee703de783 100644 --- a/types/mongoose/index.d.ts +++ b/types/mongoose/index.d.ts @@ -815,6 +815,8 @@ declare module "mongoose" { typeKey?: string; /** defaults to false */ useNestedStrict?: boolean; + /** defaults to false */ + usePushEach?: boolean; /** defaults to true */ validateBeforeSave?: boolean; /** defaults to "__v" */ From bd2218b6f6f1449636dbd32a5458c65be4ccb54b Mon Sep 17 00:00:00 2001 From: James Hegedus Date: Mon, 12 Mar 2018 20:30:25 +1100 Subject: [PATCH 0004/2144] [WIP] Next.js Context Object type --- types/next/index.d.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/types/next/index.d.ts b/types/next/index.d.ts index 036e9f58ce..3ebcb9b395 100644 --- a/types/next/index.d.ts +++ b/types/next/index.d.ts @@ -6,11 +6,23 @@ // TypeScript Version: 2.6 /// +/// import * as http from "http"; import * as url from "url"; +import * as fetch from "isomorphic-unfetch"; declare namespace next { + interface NextContext { + pathname?: string; //path section of URL + query?: any; // meant to be an object - // query string section of URL parsed as an object + asPath?: string; // String of the actual path (including the query) shows in the browser + req?: http.IncomingMessage; //HTTP request object (server only) + res?: http.ServerResponse; //HTTP response object (server only) + jsonPageRes?: fetch.IsomorphicResponse; //Fetch Response object (client only) - from https://developer.mozilla.org/en-US/docs/Web/API/Response + err?: Error; //Error object if any error is encountered during the rendering + } + type UrlLike = url.UrlObject | url.Url; interface ServerConfig { From bcf98ec1f542feb91866a95818824960ec0c796f Mon Sep 17 00:00:00 2001 From: James Hegedus Date: Mon, 12 Mar 2018 20:38:23 +1100 Subject: [PATCH 0005/2144] add self to receive update notifications --- types/next/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/next/index.d.ts b/types/next/index.d.ts index 3ebcb9b395..a6cf91ddc6 100644 --- a/types/next/index.d.ts +++ b/types/next/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/zeit/next.js // Definitions by: Drew Hays // Brice BERNARD +// James Hegedus // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.6 From 4b0b64bd58aa00102f3f081a84fcc695378257c8 Mon Sep 17 00:00:00 2001 From: James Hegedus Date: Mon, 12 Mar 2018 20:43:21 +1100 Subject: [PATCH 0006/2144] fix some lint errors and answer qs from PR template --- types/next/index.d.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/types/next/index.d.ts b/types/next/index.d.ts index a6cf91ddc6..77cea7062d 100644 --- a/types/next/index.d.ts +++ b/types/next/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for next 2.4 +// Type definitions for next 5.0 // Project: https://github.com/zeit/next.js // Definitions by: Drew Hays // Brice BERNARD @@ -7,21 +7,21 @@ // TypeScript Version: 2.6 /// -/// import * as http from "http"; import * as url from "url"; import * as fetch from "isomorphic-unfetch"; declare namespace next { + // <> interface NextContext { - pathname?: string; //path section of URL + pathname?: string; // path section of URL query?: any; // meant to be an object - // query string section of URL parsed as an object asPath?: string; // String of the actual path (including the query) shows in the browser - req?: http.IncomingMessage; //HTTP request object (server only) - res?: http.ServerResponse; //HTTP response object (server only) - jsonPageRes?: fetch.IsomorphicResponse; //Fetch Response object (client only) - from https://developer.mozilla.org/en-US/docs/Web/API/Response - err?: Error; //Error object if any error is encountered during the rendering + req?: http.IncomingMessage; // HTTP request object (server only) + res?: http.ServerResponse; // HTTP response object (server only) + jsonPageRes?: fetch.IsomorphicResponse; // Fetch Response object (client only) - from https://developer.mozilla.org/en-US/docs/Web/API/Response + err?: Error; // Error object if any error is encountered during the rendering } type UrlLike = url.UrlObject | url.Url; From 9d5535358fca3d705712f53da4fcd80f01600822 Mon Sep 17 00:00:00 2001 From: Ajay Shrestha Date: Tue, 13 Mar 2018 19:59:23 +0545 Subject: [PATCH 0007/2144] Initial Commit for tlds types --- types/tlds/index.d.ts | 4 ++++ types/tlds/tlds-tests.ts | 4 ++++ types/tlds/tsconfig.json | 23 +++++++++++++++++++++++ types/tlds/tslint.json | 8 ++++++++ 4 files changed, 39 insertions(+) create mode 100644 types/tlds/index.d.ts create mode 100644 types/tlds/tlds-tests.ts create mode 100644 types/tlds/tsconfig.json create mode 100644 types/tlds/tslint.json diff --git a/types/tlds/index.d.ts b/types/tlds/index.d.ts new file mode 100644 index 0000000000..615ce3f0eb --- /dev/null +++ b/types/tlds/index.d.ts @@ -0,0 +1,4 @@ +declare module "tlds" { + const c:Array; + export default c; +} diff --git a/types/tlds/tlds-tests.ts b/types/tlds/tlds-tests.ts new file mode 100644 index 0000000000..8ed622828d --- /dev/null +++ b/types/tlds/tlds-tests.ts @@ -0,0 +1,4 @@ +import * as tlds from 'tlds'; + +tlds; // all list of tlds +'[object Array]' == {}.toString.call(tlds); // tlds is an array \ No newline at end of file diff --git a/types/tlds/tsconfig.json b/types/tlds/tsconfig.json new file mode 100644 index 0000000000..fcb5c747c0 --- /dev/null +++ b/types/tlds/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "tlds-tests.ts" + ] +} \ No newline at end of file diff --git a/types/tlds/tslint.json b/types/tlds/tslint.json new file mode 100644 index 0000000000..d335520e13 --- /dev/null +++ b/types/tlds/tslint.json @@ -0,0 +1,8 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + "no-empty-interface": false, + "no-unnecessary-class": false, + "no-unnecessary-generics": false + } +} From 7847087c794c7e9b3ab7f65aad9432905770c87f Mon Sep 17 00:00:00 2001 From: Ajay Shrestha Date: Tue, 13 Mar 2018 20:47:19 +0545 Subject: [PATCH 0008/2144] Refactor type --- types/tlds/index.d.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/types/tlds/index.d.ts b/types/tlds/index.d.ts index 615ce3f0eb..2d62ba5a27 100644 --- a/types/tlds/index.d.ts +++ b/types/tlds/index.d.ts @@ -1,4 +1 @@ -declare module "tlds" { - const c:Array; - export default c; -} +export declare const tlds: string[]; \ No newline at end of file From a1dd23a169bd7a6ff23b2bce356b944c8e9bb7b1 Mon Sep 17 00:00:00 2001 From: Ajay Shrestha Date: Tue, 20 Mar 2018 20:47:08 +0545 Subject: [PATCH 0009/2144] Adding comments nad typescript version for passing Travis CI --- types/tlds/index.d.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/types/tlds/index.d.ts b/types/tlds/index.d.ts index 2d62ba5a27..ccec15f9f8 100644 --- a/types/tlds/index.d.ts +++ b/types/tlds/index.d.ts @@ -1 +1,9 @@ +// Type definitions for tlds +// Project: https://github.com/stephenmathieson/node-tlds +// Definitions by: Ajay Gopal Shrestha +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.6 +/* +Declaring const tlds and exporting it +*/ export declare const tlds: string[]; \ No newline at end of file From 8c83c926a268af5310e2da058514a6122989ee76 Mon Sep 17 00:00:00 2001 From: Ajay Shrestha Date: Tue, 20 Mar 2018 20:58:54 +0545 Subject: [PATCH 0010/2144] Fixing Travis CI build error --- types/tlds/index.d.ts | 2 +- types/tlds/tlds-tests.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/types/tlds/index.d.ts b/types/tlds/index.d.ts index ccec15f9f8..14711a2d19 100644 --- a/types/tlds/index.d.ts +++ b/types/tlds/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for tlds +// Type definitions for tlds 1.199.0 // Project: https://github.com/stephenmathieson/node-tlds // Definitions by: Ajay Gopal Shrestha // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped diff --git a/types/tlds/tlds-tests.ts b/types/tlds/tlds-tests.ts index 8ed622828d..5a0c452792 100644 --- a/types/tlds/tlds-tests.ts +++ b/types/tlds/tlds-tests.ts @@ -1,4 +1,4 @@ import * as tlds from 'tlds'; tlds; // all list of tlds -'[object Array]' == {}.toString.call(tlds); // tlds is an array \ No newline at end of file +'[object Array]' === {}.toString.call(tlds); // tlds is an array From 3467b281b3f7032ac596f464bfb69df95a000bd1 Mon Sep 17 00:00:00 2001 From: Ajay Shrestha Date: Tue, 20 Mar 2018 21:07:45 +0545 Subject: [PATCH 0011/2144] Travis issue fixed --- types/tlds/index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/types/tlds/index.d.ts b/types/tlds/index.d.ts index 14711a2d19..4e567771d4 100644 --- a/types/tlds/index.d.ts +++ b/types/tlds/index.d.ts @@ -1,9 +1,9 @@ -// Type definitions for tlds 1.199.0 +// Type definitions for tlds 1.199 // Project: https://github.com/stephenmathieson/node-tlds // Definitions by: Ajay Gopal Shrestha // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.6 -/* +/* Declaring const tlds and exporting it */ -export declare const tlds: string[]; \ No newline at end of file +export const tlds: string[]; From 34026b93c0468e1428770d964bae94e56c1eee8c Mon Sep 17 00:00:00 2001 From: Kiyotoshi Ichikawa Date: Thu, 5 Apr 2018 13:03:08 -0400 Subject: [PATCH 0012/2144] [browser-sync] Type definition for Option type is missing many valid properties. Also appending tests to cover newly added properties/interfaces. --- types/browser-sync/browser-sync-tests.ts | 276 +++++++++++++++++++++-- types/browser-sync/index.d.ts | 147 +++++++++--- 2 files changed, 379 insertions(+), 44 deletions(-) diff --git a/types/browser-sync/browser-sync-tests.ts b/types/browser-sync/browser-sync-tests.ts index bcd829367a..613f8aee25 100644 --- a/types/browser-sync/browser-sync-tests.ts +++ b/types/browser-sync/browser-sync-tests.ts @@ -8,11 +8,98 @@ import browserSync = require("browser-sync"); })(); browserSync({ - server: { - baseDir: "./" + ui: true +}); + +browserSync({ + ui: { + port: 9000, + weinre: { + port: 9001 + } } }); +browserSync({ + files: "app/css/style.css" +}); + +browserSync({ + files: [ + "app/css/style.css", + "app/js/*.js" + ] +}); + +browserSync({ + files: [ + "app/css/style.css", + "!app/js/*.js" + ] +}); + +browserSync({ + files: [ + "wp-content/themes/**/*.css", + { + match: ["wp-content/themes/**/*.css"], + fn: function (event, file) { + /** Custom event handler **/ + } + } + ] +}); + +browserSync({ + watchEvents: [ + "change", + "add", + "unlink", + "addDir", + "unlinkDir" + ] +}); + +browserSync({ + watch: true +}); + +browserSync({ + ignore: [ + "app/js/*.js" + ] +}); + +browserSync({ + single: true +}); + +browserSync({ + watchOptions: { + ignoreInitial: true, + ignored: '*.txt' + }, + files: ['./app'] +}); + +browserSync({ + files: [ + { + match: ["wp-content/themes/**/*.php"], + fn: function (event, file) { + /** Custom event handler **/ + }, + options: { + ignored: '*.txt' + } + } + ] +}); + +browserSync({ + server: "app" +}); + // multiple base directory browserSync({ server: { @@ -20,6 +107,39 @@ browserSync({ } }); +browserSync({ + server: true +}); + +browserSync({ + server: { + baseDir: "./" + } +}); + +browserSync({ + server: { + baseDir: "./", + index: "index.htm" + } +}); + +browserSync({ + server: { + baseDir: "./", + directory: true + } +}); + +browserSync({ + server: { + baseDir: "app", + serveStaticOptions: { + extensions: ["html"] + } + } +}); + browserSync({ proxy: "yourlocal.dev" }); @@ -27,8 +147,8 @@ browserSync({ browserSync({ proxy: { target: "http://yourlocal.dev", - proxyReq: function(proxyReq) { - console.log(proxyReq); + proxyReq: function (proxyReq) { + console.log(proxyReq); } } }); @@ -37,7 +157,7 @@ browserSync({ proxy: { target: "http://yourlocal.dev", proxyReq: [ - function(proxyReq) { + function (proxyReq) { console.log(proxyReq); } ] @@ -47,7 +167,7 @@ browserSync({ browserSync({ proxy: { target: "http://yourlocal.dev", - proxyRes: function(proxyRes, req, res) { + proxyRes: function (proxyRes, req, res) { console.log(proxyRes); } } @@ -57,13 +177,137 @@ browserSync({ proxy: { target: "http://yourlocal.dev", proxyRes: [ - function(proxyRes, req, res) { + function (proxyRes, req, res) { console.log(proxyRes); } ] } }); +browserSync({ + proxy: "https://yourlocal.dev", + https: { + key: "./path/to/the/key/file.key", + cert: "./path/to/the/cert/file.cer" + } +}); + +browserSync({ + port: 3000 +}); + +browserSync({ + proxy: "http://yourlocal.dev", + serveStatic: ['.', './app/css'] +}); + +browserSync({ + proxy: "http://yourlocal.dev", + serveStatic: [{ + route: '/assets', + dir: 'tmp' + }] +}); + +browserSync({ + proxy: "http://yourlocal.dev", + serveStatic: [{ + route: ['/assets', '/content'], + dir: 'tmp' + }] +}); + +browserSync({ + proxy: "http://yourlocal.dev", + serveStatic: [{ + route: '/assets', + dir: ['./tmp', './app'] + }] +}); + +browserSync({ + serveStatic: ['.', './app', './temp'], + serveStaticOptions: { + extensions: ['html'] // pretty urls + } +}); + +browserSync({ + https: true +}); + +browserSync({ + server: "./app", + https: true +}); + +browserSync({ + server: "./app", + https: { + key: "./path/to/the/key/file.key", + cert: "./path/to/the/cert/file.cer" + } +}); + +browserSync({ + httpModule: "http2" +}); + +browserSync({ + ghostMode: { + clicks: true, + scroll: true, + forms: { + inputs: true, + submit: true, + toggles: true + } + }, + proxy: "https://yourlocal.dev" +}); + +/** + * Not testing a bunch because they are either only string or boolean types. + * ....Also just got lazy and tired of writing the simple ones. + */ + +browserSync({ + snippetOptions: { + + // Ignore all HTML files within the templates folder + blacklist: [ + "templates/*.html" + ], + // Provide a custom Regex for inserting the snippet. + rule: { + match: /<\/body>/i, + fn: function (snippet, match) { + return snippet + match; + } + } + } +}); + +browserSync({ + rewriteRules: [ + { + match: /Browsersync/g, + fn: function (req, res, match) { + return 'kittenz'; + } + } + ] +}); + +browserSync({ + rewriteRules: [ + { + match: /(cats|kitten[sz]) are mediocre/g, + replace: "$1 are excellent" + } + ] +}); + var config = { server: { baseDir: "./" @@ -84,13 +328,13 @@ browserSync(config, function (err, bs) { browserSync.reload(); // single file -browserSync.reload( "styles.css" ); +browserSync.reload("styles.css"); // multiple files -browserSync.reload( ["styles.css", "ie.css"] ); +browserSync.reload(["styles.css", "ie.css"]); // streams support -browserSync.reload( { stream: true } ); +browserSync.reload({ stream: true }); browserSync.notify("Compiling, please wait!"); @@ -143,19 +387,19 @@ browser.exit(); browser.stream(); // -- "once" option. -browser.stream({once: true}); +browser.stream({ once: true }); // -- "match" option (string). -browser.stream({match: "**/*.js"}); +browser.stream({ match: "**/*.js" }); // -- "match" option (RegExp). -browser.stream({match: /\.js$/}); +browser.stream({ match: /\.js$/ }); // -- "match" option (function). -browser.stream({match: (testString) => true}); +browser.stream({ match: (testString) => true }); // -- "match" option (array). -browser.stream({match: ["**/*.js", /\.js$/, (testString) => true]}); +browser.stream({ match: ["**/*.js", /\.js$/, (testString) => true] }); // -- Both options. -browser.stream({once: true, match: ["**/*.js", /\.js$/, (testString) => true]}); +browser.stream({ once: true, match: ["**/*.js", /\.js$/, (testString) => true] }); diff --git a/types/browser-sync/index.d.ts b/types/browser-sync/index.d.ts index b22054c367..3b97fc8616 100644 --- a/types/browser-sync/index.d.ts +++ b/types/browser-sync/index.d.ts @@ -1,16 +1,21 @@ // Type definitions for browser-sync // Project: http://www.browsersync.io/ -// Definitions by: Asana , Joe Skeen +// Definitions by: Asana , +// Joe Skeen // Thomas "Thasmo" Deinhamer +// Kiyotoshi Ichikawa // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 /// /// +/// import * as chokidar from "chokidar"; import * as fs from "fs"; import * as http from "http"; import * as mm from "micromatch"; +import { ServeStaticOptions } from "serve-static"; declare namespace browserSync { interface Options { @@ -20,7 +25,7 @@ declare namespace browserSync { * * port - Default: 3001 * weinre.port - Default: 8080 - * Note: requires at least version 2.0.0 + * Note: Requires at least version 2.0.0. */ ui?: UIOptions | boolean; /** @@ -29,20 +34,40 @@ declare namespace browserSync { * patterns. * Default: false */ - files?: string | (string | FileCallback)[]; + files?: string | (string | FileCallback | object)[]; + /** + * Specify which file events to respond to. + * Available events: `add`, `change`, `unlink`, `addDir`, `unlinkDir` + */ + watchEvents?: string[]; + /** + * Watch files automatically. + */ + watch?: boolean; + /** + * Patterns for any watchers to ignore. + * Anything provided here will end up inside 'watchOptions.ignored'. + */ + ignore?: string[]; + /** + * Serve an index.html file for all non-asset routes. + * Useful when using client-routers. + */ + single?: boolean; /** * File watching options that get passed along to Chokidar. Check their docs for available options * Default: undefined - * Note: requires at least version 2.6.0 + * Note: Requires at least version 2.6.0. */ watchOptions?: chokidar.WatchOptions; /** * Use the built-in static server for basic HTML/JS/CSS websites. * Default: false */ - server?: ServerOptions; + server?: string | boolean | string[] | ServerOptions; /** * Proxy an EXISTING vhost. Browsersync will wrap your vhost with a proxy URL to view your site. + * Passing only a URL as a string equates to passing only target property of ProxyOptions type. * target - Default: undefined * ws - Default: undefined * middleware - Default: undefined @@ -50,25 +75,40 @@ declare namespace browserSync { * proxyRes - Default: undefined * proxyReq - Default: undefined */ - proxy?: string | boolean | ProxyOptions; + proxy?: string | ProxyOptions; /** * Use a specific port (instead of the one auto-detected by Browsersync) * Default: 3000 */ port?: number; + /** + * Functions or actual plugins used as middleware. + */ + middleware?: MiddlewareHandler | PerRouteMiddleware | (MiddlewareHandler | PerRouteMiddleware)[]; /** * Add additional directories from which static files should be served. * Should only be used in proxy or snippet mode. * Default: [] - * Note: requires at least version 2.8.0 + * Note: Requires at least version 2.8.0. */ - serveStatic?: string[]; + serveStatic?: (string | { route?: string | string[], dir?: string | string[]})[]; + /** + * Options that are passed to the serve-static middleware when you use the + * string[] syntax: eg: `serveStatic: ['./app']`. + * Please see [serve-static](https://github.com/expressjs/serve-static) for details. + */ + serveStaticOptions?: ServeStaticOptions; /** * Enable https for localhost development. - * Note - this is not needed for proxy option as it will be inferred from your target url. - * Note: requires at least version 1.3.0 + * Note: This may not be needed for proxy option as it will try to infer from your target url. + * Note: If privacy error is encountered please see HttpsOptions below, setting those will resolve. + * Note: Requires at least version 1.3.0. */ - https?: boolean; + https?: boolean | HttpsOptions; + /** + * Override http module to allow using 3rd party server modules (such as http2). + */ + httpModule?: string; /** * Clicks, Scrolls & Form inputs on any device will be mirrored to all others. * clicks - Default: true @@ -84,7 +124,7 @@ declare namespace browserSync { /** * Change the console logging prefix. Useful if you're creating your own project based on Browsersync * Default: BS - * Note: requires at least version 1.5.1 + * Note: Requires at least version 1.5.1. */ logPrefix?: string; /** @@ -100,19 +140,19 @@ declare namespace browserSync { /** * Log the snippet to the console when you're in snippet mode (no proxy/server) * Default: true - * Note: requires at least version 1.5.2 + * Note: Requires at least version 1.5.2. */ logSnippet?: boolean; /** * You can control how the snippet is injected onto each page via a custom regex + function. * You can also provide patterns for certain urls that should be ignored from the snippet injection. - * Note: requires at least version 2.0.0 + * Note: Requires at least version 2.0.0. */ snippetOptions?: SnippetOptions; /** * Add additional HTML rewriting rules. * Default: false - * Note: requires at least version 2.4.0 + * Note: Requires at least version 2.4.0. */ rewriteRules?: boolean | RewriteRules[]; /** @@ -139,7 +179,7 @@ declare namespace browserSync { /** * Add HTTP access control (CORS) headers to assets served by Browsersync. * Default: false - * Note: requires at least version 2.16.0 + * Note: Requires at least version 2.16.0. */ cors?: boolean; /** @@ -177,12 +217,12 @@ declare namespace browserSync { /** * Sync the scroll position of any element on the page. Add any amount of CSS selectors * Default: [] - * Note: requires at least version 2.9.0 + * Note: Requires at least version 2.9.0. */ scrollElements?: string[]; /** * Default: [] - * Note: requires at least version 2.9.0 + * Note: Requires at least version 2.9.0. * Sync the scroll position of any element on the page - where any scrolled element will cause * all others to match scroll position. This is helpful when a breakpoint alters which element * is actually scrolling @@ -197,13 +237,18 @@ declare namespace browserSync { /** * Restrict the frequency in which browser:reload events can be emitted to connected clients * Default: 0 - * Note: requires at least version 2.6.0 + * Note: Requires at least version 2.6.0. */ reloadDebounce?: number; + /** + * Emit only the first event during sequential time windows of a specified duration. + * Note: Requires at least version 2.13.0. + */ + reloadThrottle?: number; /** * User provided plugins * Default: [] - * Note: requires at least version 2.6.0 + * Note: Requires at least version 2.6.0. */ plugins?: any[]; /** @@ -224,6 +269,10 @@ declare namespace browserSync { * Override host detection if you know the correct IP to use */ host?: string; + /** + * Support environments where dynamic hostnames are not required (ie: electron). + */ + localOnly?: boolean; /** * Send file-change events to the browser * Default: true @@ -234,10 +283,16 @@ declare namespace browserSync { * Default: true */ timestamps?: boolean; + /** + * ¯\_(ツ)_/¯ + * Best guess, when ghostMode (or SocketIO?) is setup the events + * listed here will be emitted and able to hook into. + */ + clientEvents?: string[]; /** * Alter the script path for complete control over where the Browsersync Javascript is served * from. Whatever you return from this function will be used as the script path. - * Note: requires at least version 1.5.0 + * Note: Requires at least version 1.5.0. */ scriptPath?: (path: string) => string; /** @@ -248,10 +303,21 @@ declare namespace browserSync { * domain - Default: undefined * port - Default: undefined * clients.heartbeatTimeout - Default: 5000 - * Note: requires at least version 1.6.2 + * Note: Requires at least version 1.6.2. */ socket?: SocketOptions; - middleware?: MiddlewareHandler | PerRouteMiddleware | (MiddlewareHandler | PerRouteMiddleware)[]; + /** + * ¯\_(ツ)_/¯ + */ + tagNames?: TagNamesOptions; + /** + * ¯\_(ツ)_/¯ + */ + injectFileTypes?: string[]; + /** + * ¯\_(ツ)_/¯ + */ + excludeFileTypes?: string[]; } interface Hash { @@ -287,6 +353,7 @@ declare namespace browserSync { routes?: Hash; /** configure custom middleware */ middleware?: (MiddlewareHandler | PerRouteMiddleware)[]; + serveStaticOptions?: ServeStaticOptions } interface ProxyOptions { @@ -298,6 +365,11 @@ declare namespace browserSync { proxyReq?: ((res: http.ServerRequest) => any)[] | ((res: http.ServerRequest) => any); } + interface HttpsOptions { + key?: string; + cert?: string; + } + interface MiddlewareHandler { (req: http.IncomingMessage, res: http.ServerResponse, next: Function): any; } @@ -310,11 +382,17 @@ declare namespace browserSync { interface GhostOptions { clicks?: boolean; scroll?: boolean; - forms?: boolean; + forms?: boolean | { + submit?: boolean; + inputs?: boolean; + toggles?: boolean; + }; } interface SnippetOptions { - ignorePaths?: string; + async?: boolean, + whitelist?: string[], + blacklist?: string[], rule?: { match?: RegExp; fn?: (snippet: string, match: string) => any }; } @@ -327,9 +405,22 @@ declare namespace browserSync { clients?: { heartbeatTimeout?: number; }; } + interface TagNamesOptions { + less?: string; + scss?: string; + css?: string; + jpg?: string; + jpeg?: string; + png?: string; + svg?: string; + gif?: string; + js?: string; + } + interface RewriteRules { match: RegExp; - fn: (match: string) => string; + replace?: string; + fn?: (req: http.IncomingMessage, res: http.ServerResponse, match: string) => string; } interface StreamOptions { @@ -342,7 +433,7 @@ declare namespace browserSync { * Start the Browsersync service. This will launch a server, proxy or start the snippet mode * depending on your use-case. */ - (config?: Options, callback?: (err: Error, bs: Object) => any): BrowserSyncInstance; + (config?: Options, callback?: (err: Error, bs: object) => any): BrowserSyncInstance; /** * Create a Browsersync instance * @param name an identifier that can used for retrieval later @@ -367,7 +458,7 @@ declare namespace browserSync { * Start the Browsersync service. This will launch a server, proxy or start the snippet mode * depending on your use-case. */ - init(config?: Options, callback?: (err: Error, bs: Object) => any): BrowserSyncInstance; + init(config?: Options, callback?: (err: Error, bs: object) => any): BrowserSyncInstance; /** * Reload the browser * The reload method will inform all browsers about changed files and will either cause the browser From 5b98aceaf1b756c021af76b43b7cabf9f16790aa Mon Sep 17 00:00:00 2001 From: Drew Diamantoukos Date: Mon, 23 Apr 2018 13:28:24 -0400 Subject: [PATCH 0013/2144] Adding pointcloud type for Plotly scatter type and sizemax for Marker --- types/plotly.js/index.d.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/types/plotly.js/index.d.ts b/types/plotly.js/index.d.ts index 9fbbeaa92f..12fe6e8e39 100644 --- a/types/plotly.js/index.d.ts +++ b/types/plotly.js/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for plotly.js 1.35 +// Type definitions for plotly.js 1.36 // Project: https://plot.ly/javascript/ // Definitions by: Chris Gervang // Martin Duparc @@ -6,6 +6,7 @@ // taoqf // Dadstart // Jared Szechy +// Drew Diamantoukos // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 @@ -354,7 +355,7 @@ export type Color = string | Array | Array Date: Mon, 23 Apr 2018 13:38:15 -0400 Subject: [PATCH 0014/2144] Added xy field for ScatterData, which is used by pointcloud --- types/plotly.js/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/plotly.js/index.d.ts b/types/plotly.js/index.d.ts index 12fe6e8e39..6b405d3e53 100644 --- a/types/plotly.js/index.d.ts +++ b/types/plotly.js/index.d.ts @@ -359,6 +359,7 @@ export interface ScatterData { x: Datum[] | Datum[][]; y: Datum[] | Datum[][]; z: Datum[] | Datum[][] | Datum[][][]; + xy: Float32Array; xaxis: string; yaxis: string; text: string | string[]; From 55194a76e4854bca216f818098be7ebd5f5b8f67 Mon Sep 17 00:00:00 2001 From: Kiyotoshi Ichikawa Date: Wed, 25 Apr 2018 15:43:30 -0400 Subject: [PATCH 0015/2144] Updated types and appended some. The proxy.proxyRes property could be further expressed to take one or three parameters. Its previous representation was not correct according to the documentation and default configuration the package generates. Specified types for watchEvents, open, and logLevel options. Converted type Object references to object per recommended guidelines of DefinitelyTyped repo. Converted type Function references to arrow function. More SnippetOptions properties, defined FormsOptions under GhostOptions. Added and modified tests. --- types/browser-sync/browser-sync-tests.ts | 28 ++++++++++-- types/browser-sync/index.d.ts | 56 +++++++++++++++++------- 2 files changed, 63 insertions(+), 21 deletions(-) diff --git a/types/browser-sync/browser-sync-tests.ts b/types/browser-sync/browser-sync-tests.ts index 613f8aee25..c63cb0c862 100644 --- a/types/browser-sync/browser-sync-tests.ts +++ b/types/browser-sync/browser-sync-tests.ts @@ -167,8 +167,8 @@ browserSync({ browserSync({ proxy: { target: "http://yourlocal.dev", - proxyRes: function (proxyRes, req, res) { - console.log(proxyRes); + proxyRes: function (proxyResponse, req, res) { + console.log(proxyResponse); } } }); @@ -177,8 +177,28 @@ browserSync({ proxy: { target: "http://yourlocal.dev", proxyRes: [ - function (proxyRes, req, res) { - console.log(proxyRes); + function (proxyResponse, req, res) { + console.log(proxyResponse); + } + ] + } +}); + +browserSync({ + proxy: { + target: "http://yourlocal.dev", + proxyRes: function (res) { + console.log(res); + } + } +}); + +browserSync({ + proxy: { + target: "http://yourlocal.dev", + proxyRes: [ + function (res) { + console.log(res); } ] } diff --git a/types/browser-sync/index.d.ts b/types/browser-sync/index.d.ts index 3b97fc8616..de0a457266 100644 --- a/types/browser-sync/index.d.ts +++ b/types/browser-sync/index.d.ts @@ -39,7 +39,7 @@ declare namespace browserSync { * Specify which file events to respond to. * Available events: `add`, `change`, `unlink`, `addDir`, `unlinkDir` */ - watchEvents?: string[]; + watchEvents?: WatchEvents | string[]; /** * Watch files automatically. */ @@ -72,7 +72,7 @@ declare namespace browserSync { * ws - Default: undefined * middleware - Default: undefined * reqHeaders - Default: undefined - * proxyRes - Default: undefined + * proxyRes - Default: undefined (http.ServerResponse if expecting single parameter) * proxyReq - Default: undefined */ proxy?: string | ProxyOptions; @@ -91,7 +91,7 @@ declare namespace browserSync { * Default: [] * Note: Requires at least version 2.8.0. */ - serveStatic?: (string | { route?: string | string[], dir?: string | string[]})[]; + serveStatic?: StaticOptions[] | string[]; /** * Options that are passed to the serve-static middleware when you use the * string[] syntax: eg: `serveStatic: ['./app']`. @@ -120,7 +120,7 @@ declare namespace browserSync { * Can be either "info", "debug", "warn", or "silent" * Default: info */ - logLevel?: string; + logLevel?: LogLevel; /** * Change the console logging prefix. Useful if you're creating your own project based on Browsersync * Default: BS @@ -170,7 +170,7 @@ declare namespace browserSync { * Decide which URL to open automatically when Browsersync starts. Defaults to "local" if none set. * Can be true, local, external, ui, ui-external, tunnel or false */ - open?: string | boolean; + open?: OpenOptions | boolean; /** * The browser(s) to open * Default: default @@ -320,6 +320,12 @@ declare namespace browserSync { excludeFileTypes?: string[]; } + type WatchEvents = "add" | "change" | "unlink" | "addDir" | "unlinkDir"; + + type LogLevel = "info" | "debug" | "warn" | "silent"; + + type OpenOptions = "local" | "external" | "ui" | "ui-external" | "tunnel"; + interface Hash { [path: string]: T; } @@ -353,16 +359,21 @@ declare namespace browserSync { routes?: Hash; /** configure custom middleware */ middleware?: (MiddlewareHandler | PerRouteMiddleware)[]; - serveStaticOptions?: ServeStaticOptions + serveStaticOptions?: ServeStaticOptions; } interface ProxyOptions { target?: string; middleware?: MiddlewareHandler; ws?: boolean; - reqHeaders?: (config: any) => Hash; - proxyRes?: ((res: http.ServerResponse, req: http.IncomingMessage, next: Function) => any)[] | ((res: http.ServerResponse, req: http.IncomingMessage, next: Function) => any); - proxyReq?: ((res: http.ServerRequest) => any)[] | ((res: http.ServerRequest) => any); + reqHeaders?: (config: object) => Hash; + proxyRes?: ProxyResponseMiddleware | ProxyResponseMiddleware[]; + proxyReq?: ((res: http.ServerRequest) => void)[] | ((res: http.ServerRequest) => void); + error?: (err: NodeJS.ErrnoException, req: http.IncomingMessage, res: http.ServerResponse) => void; + } + + interface ProxyResponseMiddleware { + (proxyRes: http.ServerResponse | http.IncomingMessage, res: http.ServerResponse, req: http.IncomingMessage): void; } interface HttpsOptions { @@ -370,11 +381,17 @@ declare namespace browserSync { cert?: string; } + interface StaticOptions { + route: string | string[], + dir: string | string[] + } + interface MiddlewareHandler { - (req: http.IncomingMessage, res: http.ServerResponse, next: Function): any; + (req: http.IncomingMessage, res: http.ServerResponse, next: () => void): any; } interface PerRouteMiddleware { + id?: string; route: string; handle: MiddlewareHandler; } @@ -382,18 +399,23 @@ declare namespace browserSync { interface GhostOptions { clicks?: boolean; scroll?: boolean; - forms?: boolean | { - submit?: boolean; - inputs?: boolean; - toggles?: boolean; - }; + forms?: FormsOptions | boolean; + } + + interface FormsOptions { + inputs: boolean, + submit: boolean, + toggles: boolean } interface SnippetOptions { - async?: boolean, + async?: boolean; whitelist?: string[], blacklist?: string[], - rule?: { match?: RegExp; fn?: (snippet: string, match: string) => any }; + rule?: { + match?: RegExp; + fn?: (snippet: string, match: string) => any + }; } interface SocketOptions { From fe2555fa262dc1d0d9110aa1c1ff7c0a3b9bf747 Mon Sep 17 00:00:00 2001 From: dvorakroth Date: Tue, 1 May 2018 08:27:21 +0000 Subject: [PATCH 0016/2144] Papaparse: added Parser.pause() & Parser.resume() --- types/papaparse/index.d.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/types/papaparse/index.d.ts b/types/papaparse/index.d.ts index ddad5970cb..d97a25010b 100644 --- a/types/papaparse/index.d.ts +++ b/types/papaparse/index.d.ts @@ -74,6 +74,9 @@ export class Parser { // Gets the cursor position getCharIndex(): number; + + pause(): void; + resume(): void; } export interface ParseConfig { From 16fe1426ca2d73ae73299e0e6a9f76c3075a65ad Mon Sep 17 00:00:00 2001 From: Resi Respati Date: Wed, 2 May 2018 00:29:28 +0700 Subject: [PATCH 0017/2144] [next] NextContext type adjustments * Add renderPage property to `NextContext` * `pathname`, `query`, and `asPath` is always defined * fixed object types, add proper JSDoc to context interface --- types/next/index.d.ts | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/types/next/index.d.ts b/types/next/index.d.ts index 77cea7062d..5ecfba20da 100644 --- a/types/next/index.d.ts +++ b/types/next/index.d.ts @@ -15,13 +15,28 @@ import * as fetch from "isomorphic-unfetch"; declare namespace next { // <> interface NextContext { - pathname?: string; // path section of URL - query?: any; // meant to be an object - // query string section of URL parsed as an object - asPath?: string; // String of the actual path (including the query) shows in the browser - req?: http.IncomingMessage; // HTTP request object (server only) - res?: http.ServerResponse; // HTTP response object (server only) - jsonPageRes?: fetch.IsomorphicResponse; // Fetch Response object (client only) - from https://developer.mozilla.org/en-US/docs/Web/API/Response - err?: Error; // Error object if any error is encountered during the rendering + /** path section of URL */ + pathname: string + /** query string section of URL parsed as an object */ + query: { + [key: string]: any + } + /** String of the actual path (including the query) shows in the browser */ + asPath: string + /** HTTP request object (server only) */ + req?: http.IncomingMessage + /** HTTP response object (server only) */ + res?: http.ServerResponse + /** Fetch Response object (client only) - from https://developer.mozilla.org/en-US/docs/Web/API/Response */ + jsonPageRes?: fetch.IsomorphicResponse + /** Error object if any error is encountered during the rendering */ + err?: Error + /** a callback that executes the actual React rendering logic (synchronously) */ + renderPage( + cb: (enhancer: () => JSX.Element) => React.ComponentType + ): { + [key: string]: any + } } type UrlLike = url.UrlObject | url.Url; From 6145af0a3acff432e4d24a5e90ec6125bce7f5b6 Mon Sep 17 00:00:00 2001 From: Resi Respati Date: Wed, 2 May 2018 00:34:12 +0700 Subject: [PATCH 0018/2144] [next] renderPage callback should be optional --- types/next/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/next/index.d.ts b/types/next/index.d.ts index 5ecfba20da..7f7c58140e 100644 --- a/types/next/index.d.ts +++ b/types/next/index.d.ts @@ -33,7 +33,7 @@ declare namespace next { err?: Error /** a callback that executes the actual React rendering logic (synchronously) */ renderPage( - cb: (enhancer: () => JSX.Element) => React.ComponentType + cb?: (enhancer: () => JSX.Element) => React.ComponentType ): { [key: string]: any } From 6509669d3dc7a6a55c76e7dbdd31ee2f596e802d Mon Sep 17 00:00:00 2001 From: dvorakroth Date: Wed, 2 May 2018 10:55:27 +0000 Subject: [PATCH 0019/2144] chart.js -- ChartPoint.y is allowed to be string and Date --- types/chart.js/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/chart.js/index.d.ts b/types/chart.js/index.d.ts index 2c5de28962..621152162a 100644 --- a/types/chart.js/index.d.ts +++ b/types/chart.js/index.d.ts @@ -166,7 +166,7 @@ declare namespace Chart { interface ChartPoint { x?: number | string | Date; - y?: number; + y?: number | string | Date; r?: number; } From 07de2cfd39a8da31d5013d77180ed45a72637ff1 Mon Sep 17 00:00:00 2001 From: Resi Respati Date: Sat, 5 May 2018 00:34:47 +0700 Subject: [PATCH 0020/2144] [next] target next@6.0.0 `next@6.0.0` is out, so let's change the target version to it --- types/next/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/next/index.d.ts b/types/next/index.d.ts index 7f7c58140e..3abb22a2a4 100644 --- a/types/next/index.d.ts +++ b/types/next/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for next 5.0 +// Type definitions for next 6.0 // Project: https://github.com/zeit/next.js // Definitions by: Drew Hays // Brice BERNARD From 3dadbaed38ad4b41eef07495e4966ea7e3811712 Mon Sep 17 00:00:00 2001 From: John Gainfort Jr Date: Sun, 6 May 2018 12:04:34 -0600 Subject: [PATCH 0021/2144] Added Partial Config Type and Verified all Config Options and API is present --- types/hls.js/hls.js-tests.ts | 2 +- types/hls.js/index.d.ts | 455 ++--------------------------------- 2 files changed, 21 insertions(+), 436 deletions(-) diff --git a/types/hls.js/hls.js-tests.ts b/types/hls.js/hls.js-tests.ts index daab1f23f2..3ba43ac3d8 100644 --- a/types/hls.js/hls.js-tests.ts +++ b/types/hls.js/hls.js-tests.ts @@ -23,7 +23,7 @@ class pLoader extends Hls.DefaultConfig.loader { if (Hls.isSupported()) { const video = document.getElementById('video'); - const hls = new Hls({ pLoader }); + const hls = new Hls({ pLoader: pLoader }); const version: string = Hls.version; hls.loadSource('http://www.streambox.fr/playlists/test_001/stream.m3u8'); hls.attachMedia(video); diff --git a/types/hls.js/index.d.ts b/types/hls.js/index.d.ts index ea26719b22..a95943e95a 100644 --- a/types/hls.js/index.d.ts +++ b/types/hls.js/index.d.ts @@ -452,15 +452,18 @@ declare namespace Hls { */ const OTHER_ERROR: string; } + /** * override Hls default configuration * this configuration will be applied by default to all instances */ let DefaultConfig: Config; + /** * checks whether your browser is supporting MediaSource Extensions */ function isSupported(): boolean; + /** * returns hls.js dist version number */ @@ -900,440 +903,6 @@ declare namespace Hls { minAutoBitrate: number; } - interface OptionalConfig { - /** - * (default: false) - * if set to true, the adaptive algorithm with limit levels usable in auto-quality by the HTML video element dimensions (width and height) - * if set to false, levels will not be limited. All available levels could be used in auto-quality mode taking only bandwidth into consideration. - */ - capLevelToPlayerSize?: boolean; - /** - * (default: false) - * setting config.debug = true; will turn on debug logs on JS console. - * a logger object could also be provided for custom logging: config.debug = customLogger; - */ - debug?: boolean; - /** - * (default: true) - * if set to true, start level playlist and first fragments will be loaded automatically, after triggering of Hls.Events.MANIFEST_PARSED event - * if set to false, an explicit API call (hls.startLoad(startPosition=-1)) will be needed to start quality level/fragment loading. - */ - autoStartLoad?: boolean; - /** - * (default -1) - * if set to -1, playback will start from initialTime=0 for VoD and according to liveSyncDuration/liveSyncDurationCount config params for Live - * otherwise, playback will start from predefined value. (unless stated otherwise in autoStartLoad=false mode : in that case startPosition can be overrided using hls.startLoad(startPosition)). - */ - startPosition?: number; - /** - * (default: undefined) - * if audio codec is not signaled in variant manifest, or if only a stream manifest is provided, hls.js tries to guess audio codec by parsing audio sampling rate in ADTS header. - * If sampling rate is less or equal than 22050 Hz, then hls.js assumes it is HE-AAC, otherwise it assumes it is AAC-LC. - * This could result in bad guess, leading to audio decode error, ending up in media error. - * It is possible to hint default audiocodec to hls.js by configuring this value as below: - * mp4a.40.2 (AAC-LC) or - * mp4a.40.5 (HE-AAC) or - * undefined (guess based on sampling rate) - */ - defaultAudioCodec?: string; - /** - * (default: 1) - * number of segments needed to start a playback of Live stream. - */ - initialLiveManifestSize?: number; - /** - * (default: 30 seconds) - * Maximum buffer length in seconds. If buffer length is/become less than this value, a new fragment will be loaded. - * This is the guaranteed buffer length hls.js will try to reach, regardless of maxBufferSize. - */ - maxBufferLength?: number; - /** - * (default 600s) - * Maximum buffer length in seconds. Hls.js will never exceed this value, even if maxBufferSize is not reached yet. - * hls.js tries to buffer up to a maximum number of bytes (60 MB by default) rather than to buffer up to a maximum nb of seconds. - * This is to mimic the browser behaviour (the buffer eviction algorithm is starting after the browser detects that video buffer size reaches a limit in bytes) - * maxBufferLength is the minimum guaranteed buffer length that hls.js will try to achieve, even if that value exceeds the amount of bytes 60 MB of memory. - * maxMaxBufferLength acts as a capping value, as if bitrate is really low, you could need more than one hour of buffer to fill 60 MB. - */ - maxMaxBufferLength?: number; - /** - * (default: 60 MB) - * 'Minimum' maximum buffer size in bytes. If buffer size upfront is bigger than this value, no fragment will be loaded - */ - maxBufferSize?: number; - /** - * (default: 0.5 seconds) - * 'Maximum' inter-fragment buffer hole tolerance that hls.js can cope with when searching for the next fragment to load. When switching between quality level, - * fragments might not be perfectly aligned. - * This could result in small overlapping or hole in media buffer. This tolerance factor helps cope with this. - */ - maxBufferHole?: number; - /** - * (default: 2s) - * In case playback is stalled, and a buffered range is available upfront, less than maxSeekHole seconds from current media position, - * hls.js will jump over this buffer hole to reach the beginning of this following buffered range. - * maxSeekHole allows to configure this jumpable threshold. - */ - maxSeekHole?: number; - /** - * (default: 4s) - * - * ABR algorithm will always try to choose a quality level that should avoid rebuffering. In case no quality level with this criteria can - * be found (lets say for example that buffer length is 1s, but fetching a fragment at lowest quality is predicted to take around 2s ... - * ie we can forecast around 1s of rebuffering ...) then ABR algorithm will try to find a level that should guarantee less than - * maxStarvationDelay of buffering. - */ - maxStarvationDelay?: number; - /** - * (default 0.2s) - * This tolerance factor is used during fragment lookup. - * Instead of checking whether buffered.end is located within [start, end] range, frag lookup will be done by checking within [start-maxFragLookUpTolerance, end-maxFragLookUpTolerance] range. - * This tolerance factor is used to cope with situations like: - * buffered.end = 9.991 - * frag[0] : [0,10] - * frag[1] : [10,20] - * buffered.end is within frag[0] range, but as we are close to frag[1], frag[1] should be choosen instead - * If maxFragLookUpTolerance = 0.2, this lookup will be adjusted to - * frag[0] : [-0.2,9.8] - * frag[1] : [9.8,19.8] - * This time, buffered.end is within frag[1] range, and frag[1] will be the next fragment to be loaded, as expected - */ - maxLoadingDelay?: number; - /** - * (default: 0.5s) - * media element is expected to play and if currentTime has not moved for more than lowBufferWatchdogPeriod and if there are less than maxBufferHole seconds buffered upfront, - * hls.js will try to nudge playhead to recover playback - */ - lowBufferWatchdogPeriod?: number; - /** - * (default: 3s) - * if media element is expected to play and if currentTime has not moved for more than highBufferWatchdogPeriod and if there are more than maxBufferHole seconds buffered upfront, - * hls.js will try to nudge playhead to recover playback - */ - highBufferWatchdogPeriod?: number; - /** - * (default: 0.1s) - * In case playback continues to stall after first playhead nudging, currentTime will be nudged evenmore following nudgeOffset to try to restore playback. - * media.currentTime += (nb nudge retry -1)*nudgeOffset - */ - nudgeOffset?: number; - /** - * (default: 3s) - * In case playback continues to stall after first playhead nudging, currentTime will be nudged evenmore following nudgeOffset to try to restore playback. - * media.currentTime += (nb nudge retry -1)*nudgeOffset - */ - nudgeMaxRetry?: number; - /** - * (default 4s) - * - * max video loading delay used in automatic start level selection : in that mode ABR controller will ensure that video loading time (ie - * the time to fetch the first fragment at lowest quality level + the time to fetch the fragment at the appropriate quality level is less - * than maxLoadingDelay ) - */ - maxFragLookUpTolerance?: number; - /** - * (default: 3) - * edge of live delay, expressed in multiple of EXT-X-TARGETDURATION. if set to 3, playback will start from fragment N-3, N being the last fragment of the live playlist. - * Decreasing this value is likely to cause playback stalls. - */ - liveSyncDurationCount?: number; - /** - * (default: Infinity) - * maximum delay allowed from edge of live, expressed in multiple of EXT-X-TARGETDURATION. - * If set to 10, the player will seek back to liveSyncDurationCount whenever the next fragment to be loaded is older than N-10, N being the last fragment of the live playlist. - * If set, this value must be stricly superior to liveSyncDurationCount a value too close from liveSyncDurationCount is likely to cause playback stalls. - */ - liveMaxLatencyDurationCount?: number; - /** - * (default: undefined) - * Alternative parameter to liveSyncDurationCount, expressed in seconds vs number of segments. - * If defined in the configuration object, liveSyncDuration will take precedence over the default liveSyncDurationCount. - * You can't define this parameter and either liveSyncDurationCount or liveMaxLatencyDurationCount in your configuration object at the same time. - * A value too low (inferior to ~3 segment durations) is likely to cause playback stalls. - */ - liveSyncDuration?: number; - /** - * (default: undefined) - * Alternative parameter to liveMaxLatencyDurationCount, expressed in seconds vs number of segments. - * If defined in the configuration object, liveMaxLatencyDuration will take precedence over the default liveMaxLatencyDurationCount. - * If set, this value must be stricly superior to liveSyncDuration which must be defined as well. - * You can't define this parameter and either liveSyncDurationCount or liveMaxLatencyDurationCount in your configuration object at the same time. - * A value too close from liveSyncDuration is likely to cause playback stalls. - */ - liveMaxLatencyDuration?: number; - /** - * (default: false) - * Override current Media Source duration to Infinity for a live broadcast. Useful, if you are building a player which relies - * on native UI capabilities in modern browsers. If you want to have a native Live UI in environments like iOS Safari, Safari, - * Android Google Chrome, etc. set this value to true. - */ - liveDurationInfinity?: boolean; - /** - * (default: true) - * Enable WebWorker (if available on browser) for TS demuxing/MP4 remuxing, to improve performance and avoid lag/frame drops. - */ - enableWorker?: boolean; - /** - * (default: true) - * Enable to use JavaScript version AES decryption for fallback of WebCrypto API. - */ - enableSoftwareAES?: boolean; - /** - * (default: undefined) - * When set, use this level as the default hls.startLevel. Keep in mind that the startLevel set with the API takes precedence over - * config.startLevel configuration parameter. - */ - startLevel?: number; - /** - * (default: 10000ms for level and manifest) - * URL Loader timeout. A timeout callback will be triggered if loading duration exceeds this timeout. no further action will be done : the load operation will not be cancelled/aborted. - * It is up to the application to catch this event and treat it as needed. - */ - manifestLoadingTimeOut?: number; - /** - * (default: 3) - * Max number of load retries. - */ - manifestLoadingMaxRetry?: number; - /** - * (default: 1000 ms) - * Initial delay between XMLHttpRequest error and first load retry (in ms). - * Any I/O error will trigger retries every 500ms,1s,2s,4s,8s, ... - * capped to fragLoadingMaxRetryTimeout / manifestLoadingMaxRetryTimeout / levelLoadingMaxRetryTimeout value (exponential backoff). - * Prefetch start fragment although media not attached. - */ - manifestLoadingRetryDelay?: number; - /** - * (default: 64000 ms) - * Maximum frag/manifest/key retry timeout (in milliseconds) in case I/O errors are met. - */ - manifestLoadingMaxRetryTimeout?: number; - /** - * (default: 60000ms for fragment) - * URL Loader timeout. A timeout callback will be triggered if loading duration exceeds this timeout. no further action will be done : the load operation will not be cancelled/aborted. - * It is up to the application to catch this event and treat it as needed. - */ - levelLoadingTimeOut?: number; - /** - * (default: 3) - * Max number of load retries. - */ - levelLoadingMaxRetry?: number; - /** - * (default: 1000 ms) - * Initial delay between XMLHttpRequest error and first load retry (in ms). - * Any I/O error will trigger retries every 500ms,1s,2s,4s,8s, ... - * capped to fragLoadingMaxRetryTimeout / manifestLoadingMaxRetryTimeout / levelLoadingMaxRetryTimeout value (exponential backoff). - * Prefetch start fragment although media not attached. - */ - levelLoadingRetryDelay?: number; - /** - * (default: 64000 ms) - * Maximum frag/manifest/key retry timeout (in milliseconds) in case I/O errors are met. - */ - levelLoadingMaxRetryTimeout?: number; - /** - * (default: 60000ms for fragment) - * URL Loader timeout. A timeout callback will be triggered if loading duration exceeds this timeout. no further action will be done : the load operation will not be cancelled/aborted. - * It is up to the application to catch this event and treat it as needed. - */ - fragLoadingTimeOut?: number; - /** - * (default: 3) - * Max number of load retries. - */ - fragLoadingMaxRetry?: number; - /** - * (default: 1000 ms) - * Initial delay between XMLHttpRequest error and first load retry (in ms). - * Any I/O error will trigger retries every 500ms,1s,2s,4s,8s, ... - * capped to fragLoadingMaxRetryTimeout / manifestLoadingMaxRetryTimeout / levelLoadingMaxRetryTimeout value (exponential backoff). - * Prefetch start fragment although media not attached. - */ - fragLoadingRetryDelay?: number; - /** - * (default: 64000 ms) - * Maximum frag/manifest/key retry timeout (in milliseconds) in case I/O errors are met. - */ - fragLoadingMaxRetryDelay?: number; - /** - * (default: false) - * Start prefetching start fragment although media not attached yet. Max number of append retries. - */ - startFragPrefetch?: boolean; - /** - * (default: 3) - * Max number of sourceBuffer.appendBuffer() retry upon error. Such error could happen in loop with UHD streams, when internal buffer is full. (Quota Exceeding Error will be triggered). - * In that case we need to wait for the browser to evict some data before being able to append buffer correctly. - */ - appendErrorMaxRetry?: number; - /** - * (default: standard XMLHttpRequest-based URL loader) - * Override standard URL loader by a custom one. Could be useful for P2P or stubbing (testing). - * Use this, if you want to overwrite both the fragment and the playlist loader. - * Note: If fLoader or pLoader are used, they overwrite loader! - */ - loader?: typeof Loader; - /** - * (default: undefined) - * This enables the manipulation of the fragment loader. - * Note: This will overwrite the default loader, as well as your own loader function. - */ - fLoader?: typeof Loader; - /** - * (default: undefined) - * This enables the manipulation of the playlist loader. - * Note: This will overwrite the default loader, as well as your own loader function. - */ - pLoader?: typeof Loader; - /** - * (default: undefined) - * XMLHttpRequest customization callback for default XHR based loader. - * Parameter should be a function with two arguments (xhr: XMLHttpRequest, url: string). - * If xhrSetup is specified, default loader will invoke it before calling xhr.send(). This allows user to easily modify/setup XHR. - */ - xhrSetup?(xhr: XMLHttpRequest, url: string): void; - /** - * (default: undefined) - * Fetch customization callback for Fetch based loader. - * Parameter should be a function with two arguments (context and Request Init Params). - * If fetchSetup is specified and Fetch loader is used, fetchSetup will be triggered to instantiate Request Object. This allows user to easily tweak Fetch loader. - */ - fetchSetup?(context: any, initParams: any): Request; - /** - * (default: internal ABR controller) - * Customized Adaptive Bitrate Streaming Controller. - * Parameter should be a class providing 2 getters, 2 setters and a destroy() method: - * get/set nextAutoLevel: return next auto-quality level/force next auto-quality level that should be returned (currently used for emergency switch down) - * get/set autoLevelCapping: capping/max level value that could be used by ABR Controller - * destroy(): should clean-up all used resources - */ - abrController?: AbrController; - /** - * (default: internal track timeline controller) - * Customized text track syncronization controller. - * Parameter should be a class with a destroy() method: - * destroy() : should clean-up all used resources - */ - timelineController?: TimelineController; - /** - * (default: true) - * Whether or not to enable WebVTT captions on HLS - */ - enableWebVTT?: boolean; - /** - * (default: true) - * whether or not to enable CEA-708 captions - */ - enableCEA708Captions?: boolean; - /** - * (default: English) - * Label for the text track generated for CEA-708 captions track 1. This is how it will appear in the browser's native menu for subtitles and captions. - */ - captionsTextTrack1Label?: string; - /** - * (default: en) - * RFC 3066 language code for the text track generated for CEA-708 captions track 1. - */ - captionsTextTrack1LanguagedCode?: string; - /** - * (default: Spanish) - * Label for the text track generated for CEA-708 captions track 2. This is how it will appear in the browser's native menu for subtitles and captions. - */ - captionsTextTrack2Label?: string; - /** - * (default: es) - * RFC 3066 language code for the text track generated for CEA-708 captions track 2. - */ - captionsTextTrack2LanguageCode?: string; - /** - * (default: false) - * If a segment's video track is shorter than its audio track by > min(maxSeekHole, maxBufferHole), extend the final video frame's duration to match the audio track's duration. - * This helps playback continue in certain cases that might otherwise get stuck. - */ - stretchShortVideoTrack?: boolean; - /** - * (default: 1) - * Browsers are really strict about audio frames timings. They usually play audio frames one after the other, regardless of - * the timestamps advertised in the fmp4. If audio timestamps are not consistent (consecutive audio frames too close or too far - * from each other), audio will easily drift. hls.js is restamping audio frames so that the distance between consecutive audio - * frame remains constant. If the distance is larger than the max allowed drift, hls.js will either - * * drop the next audio frame if distance is too small (if next audio frame timestamp is smaller than expected - * timestamp - max allowed drifter) - * * insert silent frames if distance is too big (next audio frame timestamp is bigger than expected - * timestamp + max allowed drift) - * Parameter should be an integer representing the max number of audio frames allowed to drifter. Keep in mind that one - * audio frame is 1024 audio samples (if using AAC), at 44.1 kHz, it gives 1024/44100 = 23ms. - */ - maxAudioFramesDrift?: number; - /** - * (default: true) - * Whether or not to force having a key frame in the first AVC sample after a discontinuity. - * If set to true, after a discontinuity, the AVC samples without any key frame will be dropped until finding one that contains a key frame. - * If set to false, all AVC samples will be kept, which can help avoid holes in the stream. - * Setting this parameter to false can also generate decoding weirdness when switching level or seeking. - */ - forceKeyFrameOnDiscontinuity?: boolean; - /** - * (default: 5.0) - * Fast bitrate Exponential moving average half-life, used to compute average bitrate for Live streams. - * Half of the estimate is based on the last abrEwmaFastLive seconds of sample history. Each of the sample is weighted by the fragment loading duration. - * parameter should be a float greater than 0 - */ - abrEwmaFastLive?: number; - /** - * (default: 9.0) - * Slow bitrate Exponential moving average half-life, used to compute average bitrate for Live streams. - * Half of the estimate is based on the last abrEwmaSlowLive seconds of sample history. Each of the sample is weighted by the fragment loading duration. - * parameter should be a float greater than abrEwmaFastLive - */ - abrEwmaSlowLive?: number; - /** - * (default: 4.0) - * Fast bitrate Exponential moving average half-life, used to compute average bitrate for VoD streams. - * Half of the estimate is based on the last abrEwmaFastVoD seconds of sample history. Each of the sample is weighted by the fragment loading duration. - * parameter should be a float greater than 0 - */ - abrEwmaFastVod?: number; - /** - * (default: 15.0) - * Slow bitrate Exponential moving average half-life, used to compute average bitrate for VoD streams. - * Half of the estimate is based on the last abrEwmaSlowVoD seconds of sample history. Each of the sample is weighted by the fragment loading duration. - * parameter should be a float greater than abrEwmaFastVoD - */ - abrEwmaSlowVod?: number; - /** - * (default: 500000) - * Default bandwidth estimate in bits/second prior to collecting fragment bandwidth samples. - * parameter should be a float - */ - abrEwmaDefaultEstimate?: number; - /** - * (default: 0.8) - * Scale factor to be applied against measured bandwidth average, to determine whether we can stay on current or lower quality level. - * If abrBandWidthFactor * bandwidth average < level.bitrate then ABR can switch to that level providing that it is equal or less than current level. - */ - abrBandWidthFactor?: number; - /** - * (default: 0.7) - * Scale factor to be applied against measured bandwidth average, to determine whether we can switch up to a higher quality level. - * If abrBandWidthUpFactor * bandwidth average < level.bitrate then ABR can switch up to that quality level. - */ - abrBandWidthUpFactor?: number; - /** - * (default: false) - * max bitrate used in ABR by avg measured bitrate i.e. if bitrate signaled in variant manifest for a given level is 2Mb/s but average bitrate measured on this level is 2.5Mb/s, - * then if config value is set to true, ABR will use 2.5 Mb/s for this quality level. - */ - abrMaxWithRealBitrate?: boolean; - /** - * (default: 0) - * Return the capping/min bandwidth value that could be used by automatic level selection algorithm. - * Useful when browser or tab of the browser is not in the focus and bandwidth drops - */ - minAutoBitrate?: number; - } - /** * a Level object represents a given quality level and contains quality level related info */ @@ -1734,7 +1303,7 @@ declare class Hls { /** * Constructor. Can be provided an HlsConfig object as default properties and or overrides */ - constructor(config?: Hls.OptionalConfig) + constructor(config?: Partial) /** * return array of available quality levels */ @@ -1816,6 +1385,22 @@ declare class Hls { * position of live sync point (ie edge of live position minus safety delay defined by hls.config.liveSyncDuration) */ liveSyncPosition: number; + /** + * get : array of subtitle tracks exposed in manifest + */ + subtitleTracks: any[]; + /** + * get/set : subtitle track id (returned by). + * Returns -1 if no track is visible. + * Set to -1 to hide all subtitle tracks. + */ + subtitleTrack: number; + /** + * (default: false) + * get/set : if set to true the active subtitle track mode will be set to showing and the browser will display the active subtitles. + * If set to false, the mode will be set to hidden. + */ + subtitleDisplay: boolean; /** * calling this method will: * bind videoElement and hls instances From d76dea208f3c06a3a9feab2cc52ecf0b87179942 Mon Sep 17 00:00:00 2001 From: dvorakroth Date: Mon, 7 May 2018 08:24:19 +0000 Subject: [PATCH 0022/2144] chart.js -- both X and Y axes can have time-related options --- types/chart.js/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/chart.js/index.d.ts b/types/chart.js/index.d.ts index 621152162a..83bf5267fd 100644 --- a/types/chart.js/index.d.ts +++ b/types/chart.js/index.d.ts @@ -510,6 +510,7 @@ declare namespace Chart { gridLines?: GridLineOptions; barThickness?: number; scaleLabel?: ScaleTitleOptions; + time?: TimeScale; beforeUpdate?(scale?: any): void; beforeSetDimension?(scale?: any): void; beforeDataLimits?(scale?: any): void; @@ -529,7 +530,6 @@ declare namespace Chart { interface ChartXAxe extends CommonAxe { categoryPercentage?: number; barPercentage?: number; - time?: TimeScale; } // tslint:disable-next-line no-empty-interface From a47662329cfbdd2978f58a4591248069341c48df Mon Sep 17 00:00:00 2001 From: Resi Respati Date: Fri, 11 May 2018 22:38:21 +0700 Subject: [PATCH 0023/2144] Add NextStatelessComponent interface --- types/next/index.d.ts | 6 ++++++ types/next/test/next-component-tests.tsx | 26 ++++++++++++++++++++++++ types/next/tsconfig.json | 3 ++- 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 types/next/test/next-component-tests.tsx diff --git a/types/next/index.d.ts b/types/next/index.d.ts index 3abb22a2a4..52c34542ba 100644 --- a/types/next/index.d.ts +++ b/types/next/index.d.ts @@ -3,6 +3,7 @@ // Definitions by: Drew Hays // Brice BERNARD // James Hegedus +// Resi Respati // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.6 @@ -39,6 +40,11 @@ declare namespace next { } } + type NextSFC

= NextStatelessComponent

; + interface NextStatelessComponent

extends React.StatelessComponent

{ + getInitialProps?: (ctx: NextContext) => Promise; + } + type UrlLike = url.UrlObject | url.Url; interface ServerConfig { diff --git a/types/next/test/next-component-tests.tsx b/types/next/test/next-component-tests.tsx new file mode 100644 index 0000000000..33ecb6bc93 --- /dev/null +++ b/types/next/test/next-component-tests.tsx @@ -0,0 +1,26 @@ +import * as React from "react"; +import { NextStatelessComponent } from "next"; + +interface NextComponentProps { + example: string +} + +class ClassNext extends React.Component { + async getInitialProps() { + return { example: 'example' } + } + + render() { + return ( +

I'm a stateless component! {this.props.example}
+ ) + } +} + +const StatelessNext: NextStatelessComponent = ({ example }) => ( +
I'm a stateless component! {example}
+) + +StatelessNext.getInitialProps = async () => { + return { example: 'example' } +} diff --git a/types/next/tsconfig.json b/types/next/tsconfig.json index 48d3f0c8be..d22768e4a1 100644 --- a/types/next/tsconfig.json +++ b/types/next/tsconfig.json @@ -33,6 +33,7 @@ "test/next-document-tests.tsx", "test/next-link-tests.tsx", "test/next-dynamic-tests.tsx", - "test/next-router-tests.tsx" + "test/next-router-tests.tsx", + "test/next-component-tests.tsx" ] } From ba8d541851f904fba222022c449683fe5c3d6cff Mon Sep 17 00:00:00 2001 From: Resi Respati Date: Fri, 11 May 2018 22:42:03 +0700 Subject: [PATCH 0024/2144] [next] Use NodeResponse because of unfetch.IsomorphicResponse --- types/next/index.d.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/types/next/index.d.ts b/types/next/index.d.ts index 52c34542ba..d83b787b4a 100644 --- a/types/next/index.d.ts +++ b/types/next/index.d.ts @@ -11,7 +11,8 @@ import * as http from "http"; import * as url from "url"; -import * as fetch from "isomorphic-unfetch"; + +import { Response as NodeResponse } from "node-fetch"; declare namespace next { // <> @@ -29,7 +30,7 @@ declare namespace next { /** HTTP response object (server only) */ res?: http.ServerResponse /** Fetch Response object (client only) - from https://developer.mozilla.org/en-US/docs/Web/API/Response */ - jsonPageRes?: fetch.IsomorphicResponse + jsonPageRes?: NodeResponse /** Error object if any error is encountered during the rendering */ err?: Error /** a callback that executes the actual React rendering logic (synchronously) */ From 4dff7d985840fbe92101a8d5d3d8b5ccca9eb5f8 Mon Sep 17 00:00:00 2001 From: Resi Respati Date: Fri, 11 May 2018 22:51:14 +0700 Subject: [PATCH 0025/2144] [next] Added typings for `next/app` --- types/next/app.d.ts | 10 ++++++++++ types/next/test/next-app-tests.tsx | 27 +++++++++++++++++++++++++++ types/next/tsconfig.json | 1 + 3 files changed, 38 insertions(+) create mode 100644 types/next/app.d.ts create mode 100644 types/next/test/next-app-tests.tsx diff --git a/types/next/app.d.ts b/types/next/app.d.ts new file mode 100644 index 0000000000..6d10d77af8 --- /dev/null +++ b/types/next/app.d.ts @@ -0,0 +1,10 @@ +import * as React from "react"; + +export interface AppComponentProps { + Component: React.ComponentType; + pageProps: any +} + +export class Container extends React.Component {} + +export default class App

extends React.Component

{} diff --git a/types/next/test/next-app-tests.tsx b/types/next/test/next-app-tests.tsx new file mode 100644 index 0000000000..3e7c56f87c --- /dev/null +++ b/types/next/test/next-app-tests.tsx @@ -0,0 +1,27 @@ +import * as React from "react"; +import App, { Container } from "next/app"; + +interface NextComponentProps { + example: string; +} + +class TestApp extends App { + static async getInitialProps({ Component, router, ctx }: any) { + let pageProps = {}; + + if (Component.getInitialProps) { + pageProps = await Component.getInitialProps(ctx); + } + + return { pageProps }; + } + + render() { + const { Component, pageProps } = this.props; + return ( + + + + ); + } +} diff --git a/types/next/tsconfig.json b/types/next/tsconfig.json index d22768e4a1..36aef39491 100644 --- a/types/next/tsconfig.json +++ b/types/next/tsconfig.json @@ -28,6 +28,7 @@ "router.d.ts", "config.d.ts", "test/next-tests.ts", + "test/next-app-tests.tsx", "test/next-error-tests.tsx", "test/next-head-tests.tsx", "test/next-document-tests.tsx", From 3c4579913defe15ac6bd51858f88dc17e7477d3f Mon Sep 17 00:00:00 2001 From: Resi Respati Date: Fri, 11 May 2018 23:03:41 +0700 Subject: [PATCH 0026/2144] [next] run dtslint --- types/next/index.d.ts | 21 ++++++++++++--------- types/next/test/next-component-tests.tsx | 12 ++++++------ 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/types/next/index.d.ts b/types/next/index.d.ts index d83b787b4a..939dc27bdb 100644 --- a/types/next/index.d.ts +++ b/types/next/index.d.ts @@ -15,30 +15,33 @@ import * as url from "url"; import { Response as NodeResponse } from "node-fetch"; declare namespace next { - // <> + /** + * Context object used in methods like `getInitialProps()` + * <> + */ interface NextContext { /** path section of URL */ - pathname: string + pathname: string; /** query string section of URL parsed as an object */ query: { [key: string]: any - } + }; /** String of the actual path (including the query) shows in the browser */ - asPath: string + asPath: string; /** HTTP request object (server only) */ - req?: http.IncomingMessage + req?: http.IncomingMessage; /** HTTP response object (server only) */ - res?: http.ServerResponse + res?: http.ServerResponse; /** Fetch Response object (client only) - from https://developer.mozilla.org/en-US/docs/Web/API/Response */ - jsonPageRes?: NodeResponse + jsonPageRes?: NodeResponse; /** Error object if any error is encountered during the rendering */ - err?: Error + err?: Error; /** a callback that executes the actual React rendering logic (synchronously) */ renderPage( cb?: (enhancer: () => JSX.Element) => React.ComponentType ): { [key: string]: any - } + }; } type NextSFC

= NextStatelessComponent

; diff --git a/types/next/test/next-component-tests.tsx b/types/next/test/next-component-tests.tsx index 33ecb6bc93..a6e870f8e2 100644 --- a/types/next/test/next-component-tests.tsx +++ b/types/next/test/next-component-tests.tsx @@ -2,25 +2,25 @@ import * as React from "react"; import { NextStatelessComponent } from "next"; interface NextComponentProps { - example: string + example: string; } class ClassNext extends React.Component { async getInitialProps() { - return { example: 'example' } + return { example: 'example' }; } render() { return (

I'm a stateless component! {this.props.example}
- ) + ); } } const StatelessNext: NextStatelessComponent = ({ example }) => (
I'm a stateless component! {example}
-) +); StatelessNext.getInitialProps = async () => { - return { example: 'example' } -} + return { example: 'example' }; +}; From 3c5384acca044e06c4e214cf5b113b139a95cb7c Mon Sep 17 00:00:00 2001 From: Resi Respati Date: Fri, 11 May 2018 23:12:07 +0700 Subject: [PATCH 0027/2144] [next] Added AppComponentContext type --- types/next/app.d.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/types/next/app.d.ts b/types/next/app.d.ts index 6d10d77af8..512c5f996f 100644 --- a/types/next/app.d.ts +++ b/types/next/app.d.ts @@ -1,10 +1,17 @@ import * as React from "react"; +import { NextContext } from "next"; export interface AppComponentProps { Component: React.ComponentType; pageProps: any } +export interface AppComponentContext { + Component: any; + router: any; // TODO: could be SingletonRouter? + ctx: NextContext; +} + export class Container extends React.Component {} export default class App

extends React.Component

{} From f3d3de950904a3e46137c31a222e1b2d4b4d4841 Mon Sep 17 00:00:00 2001 From: Resi Respati Date: Fri, 11 May 2018 23:16:42 +0700 Subject: [PATCH 0028/2144] [next] include app.d.ts in bundle --- types/next/tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/types/next/tsconfig.json b/types/next/tsconfig.json index 36aef39491..125953fcd6 100644 --- a/types/next/tsconfig.json +++ b/types/next/tsconfig.json @@ -20,6 +20,7 @@ }, "files": [ "index.d.ts", + "app.d.ts", "document.d.ts", "dynamic.d.ts", "error.d.ts", From 92db478980b2221b31f995a0658191902ba9bb4f Mon Sep 17 00:00:00 2001 From: Resi Respati Date: Fri, 11 May 2018 23:17:40 +0700 Subject: [PATCH 0029/2144] [next] re-run dtslint --- types/next/app.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/next/app.d.ts b/types/next/app.d.ts index 512c5f996f..0296440ddb 100644 --- a/types/next/app.d.ts +++ b/types/next/app.d.ts @@ -1,9 +1,9 @@ import * as React from "react"; -import { NextContext } from "next"; +import { NextContext } from "."; export interface AppComponentProps { Component: React.ComponentType; - pageProps: any + pageProps: any; } export interface AppComponentContext { From 28b1367d70342534ff1bcd2ecedcc27b0da2f6d5 Mon Sep 17 00:00:00 2001 From: Resi Respati Date: Sat, 12 May 2018 11:51:42 +0700 Subject: [PATCH 0030/2144] [next] fix tests (getInitialProps should be static) --- types/next/test/next-component-tests.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/next/test/next-component-tests.tsx b/types/next/test/next-component-tests.tsx index a6e870f8e2..fefde092ea 100644 --- a/types/next/test/next-component-tests.tsx +++ b/types/next/test/next-component-tests.tsx @@ -6,7 +6,7 @@ interface NextComponentProps { } class ClassNext extends React.Component { - async getInitialProps() { + static async getInitialProps() { return { example: 'example' }; } From 9d68e22a0c62fbd58869ab901ad09badf8eb6dcf Mon Sep 17 00:00:00 2001 From: Resi Respati Date: Wed, 16 May 2018 21:57:28 +0700 Subject: [PATCH 0031/2144] [next] separate context objects for Document + fix tests --- types/next/document.d.ts | 13 +++++++++ types/next/index.d.ts | 6 ---- types/next/test/next-document-tests.tsx | 38 +++++++++++++++++++++---- 3 files changed, 46 insertions(+), 11 deletions(-) diff --git a/types/next/document.d.ts b/types/next/document.d.ts index 4696819626..01344de7c8 100644 --- a/types/next/document.d.ts +++ b/types/next/document.d.ts @@ -1,4 +1,5 @@ import * as React from "react"; +import { NextContext } from "."; export interface DocumentProps { __NEXT_DATA__?: any; @@ -9,6 +10,18 @@ export interface DocumentProps { [key: string]: any; } +/** + * Context object used inside `Document` + */ +export interface NextDocumentContext extends NextContext { + /** A callback that executes the actual React rendering logic (synchronously) */ + renderPage( + cb?: (enhancer: () => JSX.Element) => React.ComponentType + ): { + [key: string]: any + }; +} + export class Head extends React.Component {} export class Main extends React.Component {} export class NextScript extends React.Component {} diff --git a/types/next/index.d.ts b/types/next/index.d.ts index 939dc27bdb..6679420ba3 100644 --- a/types/next/index.d.ts +++ b/types/next/index.d.ts @@ -36,12 +36,6 @@ declare namespace next { jsonPageRes?: NodeResponse; /** Error object if any error is encountered during the rendering */ err?: Error; - /** a callback that executes the actual React rendering logic (synchronously) */ - renderPage( - cb?: (enhancer: () => JSX.Element) => React.ComponentType - ): { - [key: string]: any - }; } type NextSFC

= NextStatelessComponent

; diff --git a/types/next/test/next-document-tests.tsx b/types/next/test/next-document-tests.tsx index 0177d1d451..2b3257cd25 100644 --- a/types/next/test/next-document-tests.tsx +++ b/types/next/test/next-document-tests.tsx @@ -1,12 +1,40 @@ -import Document, * as document from "next/document"; +import Document, { Head, Main, NextScript, NextDocumentContext } from 'next/document'; import * as React from "react"; const results = ( - + - - - + +

+ ); + +const Wrapper: React.SFC = ({ children }) => {children}; + +export default class MyDocument extends Document { + static async getInitialProps({ renderPage }: NextDocumentContext) { + // Without callback + const page = renderPage(); + // With callback + const differentPage = renderPage(App => props => ); + const style = {}; + return { ...page, style }; + } + + render() { + return ( + + + My page +