From 96205f15ff82af30c84bf3e74a156e70d860eeee Mon Sep 17 00:00:00 2001 From: JounQin Date: Mon, 17 Sep 2018 17:56:45 +0800 Subject: [PATCH 01/38] [react-dom] there is no type named `Text` It should be string instead. --- types/react-dom/index.d.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/types/react-dom/index.d.ts b/types/react-dom/index.d.ts index 518c0c617c..c043439768 100644 --- a/types/react-dom/index.d.ts +++ b/types/react-dom/index.d.ts @@ -5,6 +5,7 @@ // Microsoft // MartynasZilinskas // Josh Rutherford +// JounQin // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 @@ -16,7 +17,7 @@ import { DOMAttributes, DOMElement, ReactNode, ReactPortal } from 'react'; -export function findDOMNode(instance: ReactInstance): Element | null | Text; +export function findDOMNode(instance: ReactInstance): Element | string | null; export function unmountComponentAtNode(container: Element): boolean; export function createPortal(children: ReactNode, container: Element, key?: null | string): ReactPortal; From 8e4ca1c179dd55114d4067851019399d8bc9118d Mon Sep 17 00:00:00 2001 From: Simon Schick Date: Mon, 17 Sep 2018 15:26:01 +0200 Subject: [PATCH 02/38] shot: fix headers, minor cleanup --- types/shot/index.d.ts | 27 +++++++------- types/shot/shot-tests.ts | 9 ++--- types/shot/tslint.json | 78 +--------------------------------------- 3 files changed, 19 insertions(+), 95 deletions(-) diff --git a/types/shot/index.d.ts b/types/shot/index.d.ts index 323fb5137f..70f1c738ba 100644 --- a/types/shot/index.d.ts +++ b/types/shot/index.d.ts @@ -6,8 +6,8 @@ /// -import stream = require("stream"); -import http = require("http"); +import { ServerResponse } from "http"; +import { Readable, Stream } from "stream"; interface ShotAPI { /** @@ -33,26 +33,29 @@ declare namespace Shot { * * res - a simulated response object. Inherits from node's Http.ServerResponse. * @see {@link https://github.com/hapijs/shot/blob/master/API.md#shotinjectdispatchfunc-options-callback} */ - export interface Listener { - (req: SimulatedRequestObject, res: SimulatedResponseObject): void; - } + type Listener = (req: SimulatedRequestObject, res: SimulatedResponseObject) => void; + + // disabled for backwards compat + // tslint:disable:no-empty-interface /** * a simulated request object. Inherits from Stream.Readable. * @see {@link https://github.com/hapijs/shot/blob/master/API.md#shotinjectdispatchfunc-options-callback} */ - interface SimulatedRequestObject extends stream.Readable {} + interface SimulatedRequestObject extends Readable {} /** * a simulated response object. Inherits from node's Http.ServerResponse. * @see {@link https://github.com/hapijs/shot/blob/master/API.md#shotinjectdispatchfunc-options-callback} */ - interface SimulatedResponseObject extends http.ServerResponse {} + interface SimulatedResponseObject extends ServerResponse {} + + // tslint:enable:no-empty-interface /** * @see {@link https://github.com/hapijs/shot/blob/master/API.md#shotinjectdispatchfunc-options-callback} */ - export interface RequestOptions { + interface RequestOptions { /** a string specifying the request URL. */ url: string; /** a string specifying the HTTP request method, defaulting to 'GET'. */ @@ -64,7 +67,7 @@ declare namespace Shot { /** an optional string specifying the client remote address. Defaults to '127.0.0.1'. */ remoteAddress?: string; /** an optional request payload. Can be a string, Buffer, Stream or object. */ - payload?: string | Buffer | stream.Stream | {[key: string]: any}; + payload?: string | Buffer | Stream | object; /** an object containing flags to simulate various conditions: */ simulate?: { /** indicates whether the request will fire an end event. Defaults to undefined, meaning an end event will fire. */ @@ -75,19 +78,19 @@ declare namespace Shot { error?: boolean; /** whether the request will emit a close event. Defaults to undefined, meaning no close event will be emitted. */ close?: boolean; - } + }; /** Optional flag to validate this options object. Defaults to true. */ validate?: boolean; } interface Headers { - [header: string]: string; + [header: string]: string | string[]; } /** * @see {@link https://github.com/hapijs/shot/blob/master/API.md#shotinjectdispatchfunc-options-callback} */ - export interface ResponseObject { + interface ResponseObject { /** an object containing the raw request and response objects where: */ raw: { /** the simulated request object. */ diff --git a/types/shot/shot-tests.ts b/types/shot/shot-tests.ts index 1c6749915b..3c5b2f24dd 100644 --- a/types/shot/shot-tests.ts +++ b/types/shot/shot-tests.ts @@ -9,10 +9,8 @@ import Shot = require('shot'); const internals: any = {}; -internals.main = function () { - - const dispatch = function (req: Http.IncomingMessage, res: Http.ServerResponse) { - +internals.main = () => { + const dispatch = (req: Http.IncomingMessage, res: Http.ServerResponse) => { const reply = 'Hello World'; res.writeHead(200, { 'Content-Type': 'text/plain', 'Content-Length': reply.length }); res.end(reply); @@ -20,8 +18,7 @@ internals.main = function () { const server = Http.createServer(dispatch); - Shot.inject(dispatch, { method: 'get', url: '/' }, (res) => { - + Shot.inject(dispatch, { method: 'get', url: '/', headers: { test: 'asd', test2: ['a', 'b'] } }, (res) => { console.log(res.payload); }); }; diff --git a/types/shot/tslint.json b/types/shot/tslint.json index a41bf5d19a..f93cf8562a 100644 --- a/types/shot/tslint.json +++ b/types/shot/tslint.json @@ -1,79 +1,3 @@ { - "extends": "dtslint/dt.json", - "rules": { - "adjacent-overload-signatures": false, - "array-type": false, - "arrow-return-shorthand": false, - "ban-types": false, - "callable-types": false, - "comment-format": false, - "dt-header": false, - "eofline": false, - "export-just-namespace": false, - "import-spacing": false, - "interface-name": false, - "interface-over-type-literal": false, - "jsdoc-format": false, - "max-line-length": false, - "member-access": false, - "new-parens": false, - "no-any-union": false, - "no-boolean-literal-compare": false, - "no-conditional-assignment": false, - "no-consecutive-blank-lines": false, - "no-construct": false, - "no-declare-current-package": false, - "no-duplicate-imports": false, - "no-duplicate-variable": false, - "no-empty-interface": false, - "no-for-in-array": false, - "no-inferrable-types": false, - "no-internal-module": false, - "no-irregular-whitespace": false, - "no-mergeable-namespace": false, - "no-misused-new": false, - "no-namespace": false, - "no-object-literal-type-assertion": false, - "no-padding": false, - "no-redundant-jsdoc": false, - "no-redundant-jsdoc-2": false, - "no-redundant-undefined": false, - "no-reference-import": false, - "no-relative-import-in-test": false, - "no-self-import": false, - "no-single-declare-module": false, - "no-string-throw": false, - "no-unnecessary-callback-wrapper": false, - "no-unnecessary-class": false, - "no-unnecessary-generics": false, - "no-unnecessary-qualifier": false, - "no-unnecessary-type-assertion": false, - "no-useless-files": false, - "no-var-keyword": false, - "no-var-requires": false, - "no-void-expression": false, - "no-trailing-whitespace": false, - "object-literal-key-quotes": false, - "object-literal-shorthand": false, - "one-line": false, - "one-variable-per-declaration": false, - "only-arrow-functions": false, - "prefer-conditional-expression": false, - "prefer-const": false, - "prefer-declare-function": false, - "prefer-for-of": false, - "prefer-method-signature": false, - "prefer-template": false, - "radix": false, - "semicolon": false, - "space-before-function-paren": false, - "space-within-parens": false, - "strict-export-declare-modifiers": false, - "trim-file": false, - "triple-equals": false, - "typedef-whitespace": false, - "unified-signatures": false, - "void-return": false, - "whitespace": false - } + "extends": "dtslint/dt.json" } From 7793f74543a06ea1c114dd2761d8f3259ed66e2e Mon Sep 17 00:00:00 2001 From: Simon Schick Date: Mon, 17 Sep 2018 16:46:18 +0200 Subject: [PATCH 03/38] fixup! shot: fix headers, minor cleanup --- types/shot/index.d.ts | 199 ++++++++++++++++++++---------------------- 1 file changed, 96 insertions(+), 103 deletions(-) diff --git a/types/shot/index.d.ts b/types/shot/index.d.ts index 70f1c738ba..74661b57d9 100644 --- a/types/shot/index.d.ts +++ b/types/shot/index.d.ts @@ -1,6 +1,7 @@ // Type definitions for shot 3.4 // Project: https://github.com/hapijs/shot -// Definitions by: AJP +// Definitions by: AJP +// Simon Schick // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 @@ -9,110 +10,102 @@ import { ServerResponse } from "http"; import { Readable, Stream } from "stream"; -interface ShotAPI { - /** - * Injects a fake request into an HTTP server. - * @param dispatchFunc listener function. The same as you would pass to Http.createServer when making a node HTTP server. @see IListener - * @param options request options object @see RequestOptions - * @param callback the callback function @see Callback - * @see {@link https://github.com/hapijs/shot/blob/master/API.md#shotinjectdispatchfunc-options-callback} - */ - inject(dispatchFunc: Shot.Listener, options: Shot.RequestOptions, callback: (res: Shot.ResponseObject) => void): void; +/** + * Injects a fake request into an HTTP server. + * @param dispatchFunc listener function. The same as you would pass to Http.createServer when making a node HTTP server. @see IListener + * @param options request options object @see RequestOptions + * @param callback the callback function @see Callback + * @see {@link https://github.com/hapijs/shot/blob/master/API.md#shotinjectdispatchfunc-options-callback} + */ +export function inject(dispatchFunc: Listener, options: RequestOptions, callback: (res: ResponseObject) => void): void; - /** - * Checks if given object obj is a Shot Request object. - * @see {@link https://github.com/hapijs/shot/blob/master/API.md#shotisinjectionobj} - */ - isInjection(obj: any): boolean; +/** + * Checks if given object obj is a Shot Request object. + * @see {@link https://github.com/hapijs/shot/blob/master/API.md#shotisinjectionobj} + */ +export function isInjection(obj: any): boolean; + +/** + * listener function. The same as you would pass to Http.createServer when making a node HTTP server. Has the signature function (req, res) where: + * * req - a simulated request object. Inherits from Stream.Readable. + * * res - a simulated response object. Inherits from node's Http.ServerResponse. + * @see {@link https://github.com/hapijs/shot/blob/master/API.md#shotinjectdispatchfunc-options-callback} + */ +export type Listener = (req: SimulatedRequestObject, res: SimulatedResponseObject) => void; + +// disabled for backwards compat +// tslint:disable:no-empty-interface + +/** + * a simulated request object. Inherits from Stream.Readable. + * @see {@link https://github.com/hapijs/shot/blob/master/API.md#shotinjectdispatchfunc-options-callback} + */ +export interface SimulatedRequestObject extends Readable {} + +/** + * a simulated response object. Inherits from node's Http.ServerResponse. + * @see {@link https://github.com/hapijs/shot/blob/master/API.md#shotinjectdispatchfunc-options-callback} + */ +export interface SimulatedResponseObject extends ServerResponse {} + +// tslint:enable:no-empty-interface + +/** + * @see {@link https://github.com/hapijs/shot/blob/master/API.md#shotinjectdispatchfunc-options-callback} + */ +export interface RequestOptions { + /** a string specifying the request URL. */ + url: string; + /** a string specifying the HTTP request method, defaulting to 'GET'. */ + method?: string; + /** a string specifying the HTTP HOST header value to be used if no header is provided, and the url does not include an authority component. Defaults to 'localhost'. */ + authority?: string; + /** an optional object containing request headers. */ + headers?: Headers; + /** an optional string specifying the client remote address. Defaults to '127.0.0.1'. */ + remoteAddress?: string; + /** an optional request payload. Can be a string, Buffer, Stream or object. */ + payload?: string | Buffer | Stream | object; + /** an object containing flags to simulate various conditions: */ + simulate?: { + /** indicates whether the request will fire an end event. Defaults to undefined, meaning an end event will fire. */ + end?: boolean; + /** indicates whether the request payload will be split into chunks. Defaults to `undefined`, meaning payload will not be chunked. */ + split?: boolean; + /** whether the request will emit an error event. Defaults to undefined, meaning no error event will be emitted. If set to true, the emitted error will have a message of 'Simulated'. */ + error?: boolean; + /** whether the request will emit a close event. Defaults to undefined, meaning no close event will be emitted. */ + close?: boolean; + }; + /** Optional flag to validate this options object. Defaults to true. */ + validate?: boolean; } -declare namespace Shot { - /** - * listener function. The same as you would pass to Http.createServer when making a node HTTP server. Has the signature function (req, res) where: - * * req - a simulated request object. Inherits from Stream.Readable. - * * res - a simulated response object. Inherits from node's Http.ServerResponse. - * @see {@link https://github.com/hapijs/shot/blob/master/API.md#shotinjectdispatchfunc-options-callback} - */ - type Listener = (req: SimulatedRequestObject, res: SimulatedResponseObject) => void; - - // disabled for backwards compat - // tslint:disable:no-empty-interface - - /** - * a simulated request object. Inherits from Stream.Readable. - * @see {@link https://github.com/hapijs/shot/blob/master/API.md#shotinjectdispatchfunc-options-callback} - */ - interface SimulatedRequestObject extends Readable {} - - /** - * a simulated response object. Inherits from node's Http.ServerResponse. - * @see {@link https://github.com/hapijs/shot/blob/master/API.md#shotinjectdispatchfunc-options-callback} - */ - interface SimulatedResponseObject extends ServerResponse {} - - // tslint:enable:no-empty-interface - - /** - * @see {@link https://github.com/hapijs/shot/blob/master/API.md#shotinjectdispatchfunc-options-callback} - */ - interface RequestOptions { - /** a string specifying the request URL. */ - url: string; - /** a string specifying the HTTP request method, defaulting to 'GET'. */ - method?: string; - /** a string specifying the HTTP HOST header value to be used if no header is provided, and the url does not include an authority component. Defaults to 'localhost'. */ - authority?: string; - /** an optional object containing request headers. */ - headers?: Headers; - /** an optional string specifying the client remote address. Defaults to '127.0.0.1'. */ - remoteAddress?: string; - /** an optional request payload. Can be a string, Buffer, Stream or object. */ - payload?: string | Buffer | Stream | object; - /** an object containing flags to simulate various conditions: */ - simulate?: { - /** indicates whether the request will fire an end event. Defaults to undefined, meaning an end event will fire. */ - end?: boolean; - /** indicates whether the request payload will be split into chunks. Defaults to `undefined`, meaning payload will not be chunked. */ - split?: boolean; - /** whether the request will emit an error event. Defaults to undefined, meaning no error event will be emitted. If set to true, the emitted error will have a message of 'Simulated'. */ - error?: boolean; - /** whether the request will emit a close event. Defaults to undefined, meaning no close event will be emitted. */ - close?: boolean; - }; - /** Optional flag to validate this options object. Defaults to true. */ - validate?: boolean; - } - - interface Headers { - [header: string]: string | string[]; - } - - /** - * @see {@link https://github.com/hapijs/shot/blob/master/API.md#shotinjectdispatchfunc-options-callback} - */ - interface ResponseObject { - /** an object containing the raw request and response objects where: */ - raw: { - /** the simulated request object. */ - req: SimulatedRequestObject; - /** the simulated response object. */ - res: SimulatedResponseObject; - }; - /** an object containing the response headers. */ - headers: Headers; - /** the HTTP status code. */ - statusCode: number; - /** the HTTP status message. */ - statusMessage: string; - /** the payload as a UTF-8 encoded string. */ - payload: string; - /** the raw payload as a Buffer. */ - rawPayload: Buffer; - /** an object containing the response trailers. */ - trailers: {[index: string]: any}; - } +export interface Headers { + [header: string]: string | string[]; } -declare var Shot: ShotAPI; - -export = Shot; +/** + * @see {@link https://github.com/hapijs/shot/blob/master/API.md#shotinjectdispatchfunc-options-callback} + */ +export interface ResponseObject { + /** an object containing the raw request and response objects where: */ + raw: { + /** the simulated request object. */ + req: SimulatedRequestObject; + /** the simulated response object. */ + res: SimulatedResponseObject; + }; + /** an object containing the response headers. */ + headers: Headers; + /** the HTTP status code. */ + statusCode: number; + /** the HTTP status message. */ + statusMessage: string; + /** the payload as a UTF-8 encoded string. */ + payload: string; + /** the raw payload as a Buffer. */ + rawPayload: Buffer; + /** an object containing the response trailers. */ + trailers: {[index: string]: any}; +} From 7523a10a8ff2873460a1fea9610012007c6cf05f Mon Sep 17 00:00:00 2001 From: denis Date: Mon, 17 Sep 2018 20:25:28 +0200 Subject: [PATCH 04/38] add JsDoc and activate strictNullChecks --- types/d3-interpolate/d3-interpolate-tests.ts | 90 +++++-- types/d3-interpolate/index.d.ts | 265 +++++++++++++++++-- types/d3-interpolate/tsconfig.json | 2 +- types/d3-interpolate/tslint.json | 1 - 4 files changed, 305 insertions(+), 53 deletions(-) diff --git a/types/d3-interpolate/d3-interpolate-tests.ts b/types/d3-interpolate/d3-interpolate-tests.ts index cdf338aaa4..88aba03604 100644 --- a/types/d3-interpolate/d3-interpolate-tests.ts +++ b/types/d3-interpolate/d3-interpolate-tests.ts @@ -12,8 +12,12 @@ import * as d3Hsv from 'd3-hsv'; // Preparatory steps ------------------------------------------------------------------- -interface Interpolator { - (t: number): T; +type Interpolator = (t: number) => T; + +interface Xyz { + x: number; + y: number; + z: number; } class NumCoercible { @@ -39,13 +43,17 @@ class StringCoercible { } } +let iNull: Interpolator; +let iBoolean: Interpolator; let iNum: Interpolator; let iString: Interpolator; let iDate: Interpolator; let iArrayNum: Interpolator; let iArrayStr: Interpolator; let iArrayMixed: Interpolator<[Date, string]>; +let iMix: Interpolator; let iKeyVal: Interpolator<{ [key: string]: any }>; +let iXyz: Interpolator; let iRGBColorObj: Interpolator; let iZoom: d3Interpolate.ZoomInterpolator; @@ -54,12 +62,20 @@ let str: string; let arrNum: number[]; let arrStr: string[]; let objKeyVal: { [key: string]: any }; +let xyz: Xyz; let objRGBColor: d3Color.RGBColor; let zoom: [number, number, number]; // test interpolate(a, b) signature ---------------------------------------------------- -iNum = d3Interpolate.interpolate('1', 5); +// $ExpectError +iNum = d3Interpolate.interpolate('1', 5); // fails, https://github.com/Microsoft/TypeScript/issues/4002#issuecomment-124201510 + +// null and boolean interpolator +iNull = d3Interpolate.interpolate(null, null); +iNull = d3Interpolate.interpolate(10, null); +iBoolean = d3Interpolate.interpolate(false, true); +iBoolean = d3Interpolate.interpolate("10", true); // color interpolator returning a color string iString = d3Interpolate.interpolate('seagreen', d3Color.rgb(100, 100, 100)); @@ -87,32 +103,34 @@ iNum = d3Interpolate.interpolate(new NumCoercible(2), new NumCoercible(20)); // Key Value iKeyVal = d3Interpolate.interpolate({ x: 0, y: 1 }, { x: 1, y: 10, z: 100 }); +iXyz = d3Interpolate.interpolate({ x: 0, y: 1 }, { x: 1, y: 10, z: 100 }); +iXyz = d3Interpolate.interpolate({ x: 0, y: 1 }, { x: 1, y: 10, z: 100 }); d3Interpolate.interpolate(new NumCoercible(1), new NumCoercible(5)); d3Interpolate.interpolate({ a: 1 }, new NumCoercible(5)); -// test interpolateNumber(a, b) signature ---------------------------------------------------- +// test interpolateNumber(a, b) signature ---------------------------------------------- iNum = d3Interpolate.interpolateNumber(0, 100); iNum = d3Interpolate.interpolateNumber(new NumCoercible(0), new NumCoercible(100)); num = iNum(0.5); -// test interpolateNumber(a, b) signature ---------------------------------------------------- +// test interpolateNumber(a, b) signature ---------------------------------------------- iNum = d3Interpolate.interpolateRound(0, 100); iNum = d3Interpolate.interpolateRound(new NumCoercible(0), new NumCoercible(100)); num = iNum(0.5); -// test interpolateString(a, b) signature ---------------------------------------------------- +// test interpolateString(a, b) signature ---------------------------------------------- iString = d3Interpolate.interpolateString('-1', '2'); str = iString(0.5); -// test interpolateDate(a, b) signature ---------------------------------------------------- +// test interpolateDate(a, b) signature ------------------------------------------------ iDate = d3Interpolate.interpolateDate(new Date(2016, 6, 1), new Date(2016, 6, 31)); -// test interpolateArray(a, b) signature ---------------------------------------------------- +// test interpolateArray(a, b) signature ----------------------------------------------- iArrayNum = d3Interpolate.interpolateArray([1, 2], [4, 8]); // explicit typing arrNum = iArrayNum(0.5); @@ -129,39 +147,49 @@ arrStr = iArrayStr(0.5); // two element array with first element date and second element string iArrayMixed = d3Interpolate.interpolateArray<[Date, string]>([new Date(2016, 6, 1), 'b: 1'], [new Date(2016, 6, 31), 'b: 8']); -// test interpolateObject(a, b) signature ---------------------------------------------------- +// test interpolateObject(a, b) signature ---------------------------------------------- iKeyVal = d3Interpolate.interpolateObject({ x: 0, y: 1 }, { x: 1, y: 10, z: 100 }); objKeyVal = iKeyVal(0.5); +iXyz = d3Interpolate.interpolateObject({ x: 0, y: 1 }, { x: 1, y: 10, z: 100 }); +iXyz = d3Interpolate.interpolateObject({ x: 0, y: 1 }, { x: 1, y: 10, z: 100 }); +xyz = iXyz(0.5); + iRGBColorObj = d3Interpolate.interpolateObject(d3Color.rgb('steelblue'), d3Color.rgb('seagreen')); objRGBColor = iRGBColorObj(0.5); -// test interpolateTransformCss(a, b) signature ---------------------------------------------------- +// test interpolateTransformCss(a, b) signature ---------------------------------------- iString = d3Interpolate.interpolateTransformCss('rotate(0deg)', 'rotate(60deg)'); str = iString(0.5); -// test interpolateTransformSvg(a, b) signature ---------------------------------------------------- +// test interpolateTransformSvg(a, b) signature ---------------------------------------- iString = d3Interpolate.interpolateTransformSvg('rotate(0)', 'rotate(60)'); str = iString(0.5); -// test interpolateZoom(a, b) signature ---------------------------------------------------- +// test interpolateZoom(a, b) signature ------------------------------------------------ iZoom = d3Interpolate.interpolateZoom([50, 50, 300], [100, 100, 500]); zoom = iZoom(0.5); +num = iZoom.duration; console.log('Recommended transition duration = %d', iZoom.duration); -// test quantize(interpolator, n) signature ------------------------------------------------ +// test interpolateDiscrete(a, b) signature -------------------------------------------- + +iNum = d3Interpolate.interpolateDiscrete([1, 2, 3]); +iMix = d3Interpolate.interpolateDiscrete([new Date(2016, 6, 1), 'b: 2']); + +// test quantize(interpolator, n) signature -------------------------------------------- arrNum = d3Interpolate.quantize(d3Interpolate.interpolateRound(-1, 2), 4); // inferred template parameter type arrStr = d3Interpolate.quantize(d3Interpolate.interpolateString('-1', '2'), 4); // explicit template parameter typing +// $ExpectError +arrStr = d3Interpolate.quantize(d3Interpolate.interpolateRound(-1, 2), 4); // fails, due to explicit typing v argument type mismatch -// arrStr = d3Interpolate.quantize(d3Interpolate.interpolateRound(-1, 2), 4); // test fails, due to explicit typing v argument type mismatch - -// test interpolateRgb(a, b) signatures ---------------------------------------------------------------- +// test interpolateRgb(a, b) signatures ------------------------------------------------ // without gamma correction iString = d3Interpolate.interpolateRgb('seagreen', 'steelblue'); @@ -172,13 +200,13 @@ str = iString(0.5); // with gamma correction iString = d3Interpolate.interpolateRgb.gamma(2.2)('purple', 'orange'); -// test interpolateRgbBasis(color) and interpolateRgbBasisClosed(color) signatures ------------------------- +// test interpolateRgbBasis(color) and interpolateRgbBasisClosed(color) signatures ---- iString = d3Interpolate.interpolateRgbBasis(['seagreen', d3Color.rgb('steelblue'), 'rgb(100, 100, 100)']); iString = d3Interpolate.interpolateRgbBasis(['seagreen', d3Hsv.hsv('steelblue'), 'rgb(100, 100, 100)']); iString = d3Interpolate.interpolateRgbBasisClosed(['seagreen', d3Hsv.hsv('steelblue'), 'rgb(100, 100, 100)']); -// test interpolateHsl(a, b) and interpolateHslLong(a, b)---------------------------------------------------------------- +// test interpolateHsl(a, b) and interpolateHslLong(a, b)------------------------------- iString = d3Interpolate.interpolateHsl('seagreen', 'steelblue'); iString = d3Interpolate.interpolateHsl(d3Color.rgb('seagreen'), d3Color.hcl('steelblue')); @@ -188,13 +216,13 @@ iString = d3Interpolate.interpolateHslLong('seagreen', 'steelblue'); iString = d3Interpolate.interpolateHslLong(d3Color.rgb('seagreen'), d3Color.hcl('steelblue')); iString = d3Interpolate.interpolateHslLong(d3Color.rgb('seagreen'), d3Hsv.hsv('steelblue')); -// test interpolateLab(a, b) -------------------------------------------------------------------------------------------- +// test interpolateLab(a, b) ----------------------------------------------------------- iString = d3Interpolate.interpolateLab('seagreen', 'steelblue'); iString = d3Interpolate.interpolateLab(d3Color.rgb('seagreen'), d3Color.hcl('steelblue')); iString = d3Interpolate.interpolateLab(d3Color.rgb('seagreen'), d3Hsv.hsv('steelblue')); -// test interpolateHcl(a, b) and interpolateHclLong(a, b) ---------------------------------------------------------------- +// test interpolateHcl(a, b) and interpolateHclLong(a, b) ------------------------------ iString = d3Interpolate.interpolateHcl('seagreen', 'steelblue'); iString = d3Interpolate.interpolateHcl(d3Color.rgb('seagreen'), d3Color.hcl('steelblue')); @@ -204,7 +232,7 @@ iString = d3Interpolate.interpolateHclLong('seagreen', 'steelblue'); iString = d3Interpolate.interpolateHclLong(d3Color.rgb('seagreen'), d3Color.hcl('steelblue')); iString = d3Interpolate.interpolateHclLong(d3Color.rgb('seagreen'), d3Hsv.hsv('steelblue')); -// test interpolateCubehelix(a, b) and interpolateCubehelixLong(a, b) --------------------------------------------------- +// test interpolateCubehelix(a, b) and interpolateCubehelixLong(a, b) ------------------ // without gamma correction iString = d3Interpolate.interpolateCubehelix('seagreen', 'steelblue'); @@ -224,21 +252,29 @@ str = iString(0.5); // with gamma correction iString = d3Interpolate.interpolateCubehelixLong.gamma(2.2)('purple', 'orange'); -// test interpolateBasis(splineNodes) and interpolateBasisClosed(splineNodes: number[]) ---------------------------- +// test interpolateBasis(splineNodes) and interpolateBasisClosed(splineNodes) ---------- iNum = d3Interpolate.interpolateBasis([1, 50, 30, 10]); iNum = d3Interpolate.interpolateBasisClosed([1, 50, 30, 10]); +// test interpolateHue ----------------------------------------------------------------- + +iNum = d3Interpolate.interpolateHue(30, 90); + +// test piecewise ---------------------------------------------------------------------- + +iZoom = d3Interpolate.piecewise(d3Interpolate.interpolateZoom, [[50, 50, 300], [100, 100, 500]]); + iString = d3Interpolate.piecewise(d3Interpolate.interpolateRgb.gamma(2.2), ['red', 'green', 'blue']); iString = d3Interpolate.piecewise(d3Interpolate.interpolateCubehelix, ['red', 'green', 'blue']); -iZoom = d3Interpolate.piecewise(d3Interpolate.interpolateZoom, [[50, 50, 300], [100, 100, 500]]); iNum = d3Interpolate.piecewise(d3Interpolate.interpolateNumber, [1, 2, 3]); iNum = d3Interpolate.piecewise(d3Interpolate.interpolateRound, [1.1, 2.2, 3.3]); -iString = d3Interpolate.piecewise(d3Interpolate.interpolateString, ['a', 'b', 'c']); +iString = d3Interpolate.piecewise(d3Interpolate.interpolateString, ['2px', '3px', '5px']); iDate = d3Interpolate.piecewise(d3Interpolate.interpolateDate, [new Date(2018, 5, 1), new Date(2018, 5, 2), new Date(2018, 5, 3)]); -iArrayNum = d3Interpolate.piecewise(d3Interpolate.interpolateArray, [1, 2, 4, 8]); -iArrayStr = d3Interpolate.piecewise(d3Interpolate.interpolateArray, ['a', 'b', 'c', 'd']); -iArrayMixed = d3Interpolate.piecewise<[Date, string]>(d3Interpolate.interpolateArray, [new Date(2016, 6, 1), 'b: 1']); iString = d3Interpolate.piecewise(d3Interpolate.interpolateTransformCss, ['rotate(0deg)', 'rotate(60deg)']); iString = d3Interpolate.piecewise(d3Interpolate.interpolateTransformSvg, ['rotate(0)', 'rotate(60)']); + +iArrayNum = d3Interpolate.piecewise(d3Interpolate.interpolateArray, [[1, 2], [4, 8]]); +iArrayStr = d3Interpolate.piecewise(d3Interpolate.interpolateArray, [['2px', '1em'], ['3px', '1.2em']]); +iArrayMixed = d3Interpolate.piecewise<[Date, string]>(d3Interpolate.interpolateArray, [[new Date(2016, 6, 1), 'b: 1']]); diff --git a/types/d3-interpolate/index.d.ts b/types/d3-interpolate/index.d.ts index 7d8ee60252..82d4100650 100644 --- a/types/d3-interpolate/index.d.ts +++ b/types/d3-interpolate/index.d.ts @@ -1,97 +1,314 @@ -// Type definitions for D3JS d3-interpolate module 1.2 +// Type definitions for D3JS d3-interpolate module 1.3 // Project: https://github.com/d3/d3-interpolate/ -// Definitions by: Tom Wanzek , Alex Ford , Boris Yankov +// Definitions by: Tom Wanzek +// Alex Ford +// Boris Yankov +// denisname // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 -// Last module patch version validated against: 1.2.0 +// Last module patch version validated against: 1.3.2 import { ColorCommonInstance } from 'd3-color'; -// -------------------------------------------------------------------------- +// --------------------------------------------------------------------------- // Shared Type Definitions and Interfaces -// -------------------------------------------------------------------------- +// --------------------------------------------------------------------------- export interface ZoomInterpolator extends Function { (t: number): ZoomView; /** - * Recommended duration of zoom transition in ms + * Recommended duration of zoom transition in milliseconds. */ duration: number; } export interface ColorGammaInterpolationFactory extends Function { (a: string | ColorCommonInstance, b: string | ColorCommonInstance): ((t: number) => string); + /** + * Returns a new interpolator factory of the same type using the specified *gamma*. + * For example, to interpolate from purple to orange with a gamma of 2.2 in RGB space: `d3.interpolateRgb.gamma(2.2)("purple", "orange")`. + * See Eric Brasseur’s article, [Gamma error in picture scaling](https://web.archive.org/web/20160112115812/http://www.4p8.com/eric.brasseur/gamma.html), for more on gamma correction. + */ gamma(g: number): ColorGammaInterpolationFactory; } /** * Type zoomView is used to represent a numeric array with three elements. * In order of appearance the elements correspond to: - * - cx: x-coordinate of the center of the viewport - * - cy: y-coordinate of the center of the viewport + * - cx: *x*-coordinate of the center of the viewport + * - cy: *y*-coordinate of the center of the viewport * - width: size of the viewport */ export type ZoomView = [number, number, number]; -// -------------------------------------------------------------------------- +// --------------------------------------------------------------------------- // Interpolation Function Factories -// -------------------------------------------------------------------------- +// --------------------------------------------------------------------------- +/** + * Returns an `null` constant interpolator. + */ export function interpolate(a: any, b: null): ((t: number) => null); -export function interpolate(a: number | { valueOf(): number }, b: number): ((t: number) => number); -export function interpolate(a: any, b: ColorCommonInstance): ((t: number) => string); -export function interpolate(a: Date, b: Date): ((t: number) => Date); -export function interpolate(a: string | { toString(): string }, b: string): ((t: number) => string); -export function interpolate(a: any[], b: U): ((t: number) => U); -export function interpolate(a: number | { valueOf(): number }, b: { valueOf(): number }): ((t: number) => number); -export function interpolate(a: any, b: U): ((t: number) => U); // TODO: extends 'any' should become 'object' with TS 2.2+ definitions -export function interpolate(a: any, b: { [key: string]: any }): ((t: number) => { [key: string]: any }); +/** + * Returns an boolean constant interpolator of value `b`. + */ +export function interpolate(a: any, b: boolean): ((t: number) => boolean); + +/** + * Returns a `interpolateNumber` interpolator. + */ +export function interpolate(a: number | { valueOf(): number }, b: number): ((t: number) => number); + +/** + * Returns a `interpolateRgb` interpolator. + */ +export function interpolate(a: string | ColorCommonInstance, b: ColorCommonInstance): ((t: number) => string); + +/** + * Returns a `interpolateDate` interpolator. + */ +export function interpolate(a: Date, b: Date): ((t: number) => Date); + +/** + * Returns a `interpolateString` interpolator. If `b` is a string coercible to a color use use `interpolateRgb`. + */ +export function interpolate(a: string | { toString(): string }, b: string): ((t: number) => string); + +/** + * Returns a `interpolateArray` interpolator. + */ +export function interpolate(a: any[], b: U): ((t: number) => U); + +/** + * Returns a `interpolateNumber` interpolator. + */ +export function interpolate(a: number | { valueOf(): number }, b: { valueOf(): number }): ((t: number) => number); + +/** + * Returns a `interpolateObject` interpolator. + */ +export function interpolate(a: any, b: U): ((t: number) => U); + +/** + * Returns an interpolator between the two numbers `a` and `b`. + * The returned interpolator is equivalent to: `(t) => a * (1 - t) + b * t`. + */ export function interpolateNumber(a: number | { valueOf(): number }, b: number | { valueOf(): number }): ((t: number) => number); +/** + * Returns an interpolator between the two numbers `a` and `b`; the interpolator is similar to `interpolateNumber`, + * except it will round the resulting value to the nearest integer. + */ export function interpolateRound(a: number | { valueOf(): number }, b: number | { valueOf(): number }): ((t: number) => number); +/** + * Returns an interpolator between the two strings `a` and `b`. + * The string interpolator finds numbers embedded in `a` and `b`, where each number is of the form understood by JavaScript. + * A few examples of numbers that will be detected within a string: `-1`, `42`, `3.14159`, and `6.0221413e+23`. + * + * For each number embedded in `b`, the interpolator will attempt to find a corresponding number in `a`. + * If a corresponding number is found, a numeric interpolator is created using `interpolateNumber`. + * The remaining parts of the string `b` are used as a template. + * + * For example, if `a` is `"300 12px sans-serif"`, and `b` is `"500 36px Comic-Sans"`, two embedded numbers are found. + * The remaining static parts (of string `b`) are a space between the two numbers (`" "`), and the suffix (`"px Comic-Sans"`). + * The result of the interpolator at `t` = 0.5 is `"400 24px Comic-Sans"`. + */ export function interpolateString(a: string | { toString(): string }, b: string | { toString(): string }): ((t: number) => string); +/** + * Returns an interpolator between the two dates `a` and `b`. + * + * Note: *no defensive copy* of the returned date is created; the same Date instance is returned for every evaluation of the interpolator. + * No copy is made for performance reasons; interpolators are often part of the inner loop of animated transitions. + */ export function interpolateDate(a: Date, b: Date): ((t: number) => Date); export type ArrayInterpolator = ((t: number) => A); +/** + * Returns an interpolator between the two arrays `a` and `b`. Internally, an array template is created that is the same length in `b`. + * For each element in `b`, if there exists a corresponding element in `a`, a generic interpolator is created for the two elements using `interpolate`. + * If there is no such element, the static value from `b` is used in the template. + * Then, for the given parameter `t`, the template’s embedded interpolators are evaluated. The updated array template is then returned. + * + * For example, if `a` is the array `[0, 1]` and `b` is the array `[1, 10, 100]`, then the result of the interpolator for `t = 0.5` is the array `[0.5, 5.5, 100]`. + * + * Note: *no defensive copy* of the template array is created; modifications of the returned array may adversely affect subsequent evaluation of the interpolator. + * No copy is made for performance reasons; interpolators are often part of the inner loop of animated transitions. + */ export function interpolateArray(a: any[], b: A): ArrayInterpolator; -export function interpolateObject(a: any, b: U): ((t: number) => U); // TODO: extends 'any' should become 'object' with TS 2.2+ definitions -export function interpolateObject(a: { [key: string]: any }, b: { [key: string]: any }): ((t: number) => { [key: string]: any }); +/** + * Returns an interpolator between the two objects `a` and `b`. Internally, an object template is created that has the same properties as `b`. + * For each property in `b`, if there exists a corresponding property in `a`, a generic interpolator is created for the two elements using `interpolate`. + * If there is no such property, the static value from `b` is used in the template. + * Then, for the given parameter `t`, the template's embedded interpolators are evaluated and the updated object template is then returned. + * + * For example, if `a` is the object `{x: 0, y: 1}` and `b` is the object `{x: 1, y: 10, z: 100}`, the result of the interpolator for `t = 0.5` is the object `{x: 0.5, y: 5.5, z: 100}`. + * + * Note: *no defensive copy* of the template object is created; modifications of the returned object may adversely affect subsequent evaluation of the interpolator. + * No copy is made for performance reasons; interpolators are often part of the inner loop of animated transitions. + */ +export function interpolateObject(a: any, b: U): ((t: number) => U); +/** + * Returns an interpolator between the two 2D CSS transforms represented by `a` and `b`. + * Each transform is decomposed to a standard representation of translate, rotate, *x*-skew and scale; these component transformations are then interpolated. + * This behavior is standardized by CSS: see [matrix decomposition for animation](http://www.w3.org/TR/css3-2d-transforms/#matrix-decomposition). + */ export function interpolateTransformCss(a: string, b: string): ((t: number) => string); + +/** + * Returns an interpolator between the two 2D SVG transforms represented by `a` and `b`. + * Each transform is decomposed to a standard representation of translate, rotate, *x*-skew and scale; these component transformations are then interpolated. + * This behavior is standardized by CSS: see [matrix decomposition for animation](http://www.w3.org/TR/css3-2d-transforms/#matrix-decomposition). + */ export function interpolateTransformSvg(a: string, b: string): ((t: number) => string); /** - * Create Interpolator for zoom views + * Returns an interpolator between the two views `a` and `b` of a two-dimensional plane, + * based on [“Smooth and efficient zooming and panning”](http://www.win.tue.nl/~vanwijk/zoompan.pdf). + * Each view is defined as an array of three numbers: *cx*, *cy* and *width*. + * The first two coordinates *cx*, *cy* represent the center of the viewport; the last coordinate *width* represents the size of the viewport. + * + * The returned interpolator exposes a *duration* property which encodes the recommended transition duration in milliseconds. + * This duration is based on the path length of the curved trajectory through *x,y* space. + * If you want to a slower or faster transition, multiply this by an arbitrary scale factor (*V* as described in the original paper). */ export function interpolateZoom(a: ZoomView, b: ZoomView): ZoomInterpolator; +/** + * Returns a discrete interpolator for the given array of values. The returned interpolator maps `t` in `[0, 1 / n)` to values[0], + * `t` in `[1 / n, 2 / n)` to `values[1]`, and so on, where `n = values.length`. In effect, this is a lightweight quantize scale with a fixed domain of [0, 1]. + */ +export function interpolateDiscrete(values: T[]): ((t: number) => T); + +// Sampling ------------------------------------------------------------------ + +/** + * Returns `n` uniformly-spaced samples from the specified `interpolator`, where `n` is an integer greater than one. + * The first sample is always at `t = 0`, and the last sample is always at `t = 1`. + * This can be useful in generating a fixed number of samples from a given interpolator, + * such as to derive the range of a [quantize scale](https://github.com/d3/d3-scale#quantize-scales) from a [continuous interpolator](https://github.com/d3/d3-scale#interpolateWarm). + * + * Caution: this method will not work with interpolators that do not return defensive copies of their output, + * such as `d3.interpolateArray`, `d3.interpolateDate` and `d3.interpolateObject`. For those interpolators, you must wrap the interpolator and create a copy for each returned value. + */ export function quantize(interpolator: ((t: number) => T), n: number): T[]; -// Color interpolation related +// Color Spaces +/** + * Returns an RGB color space interpolator between the two colors `a` and `b` with a configurable gamma. If the gamma is not specified, it defaults to 1.0. + * The colors `a` and `b` need not be in RGB; they will be converted to RGB using [`d3.rgb`](https://github.com/d3/d3-color#rgb). The return value of the interpolator is an RGB string. + */ export const interpolateRgb: ColorGammaInterpolationFactory; +/** + * Returns a uniform nonrational B-spline interpolator through the specified array of *colors*, which are converted to RGB color space. + * Implicit control points are generated such that the interpolator returns `colors[0]` at `t = 0` and `colors[colors.length - 1]` at `t = 1`. + * Opacity interpolation is not currently supported. See also `d3.interpolateBasis`, and see [d3-scale-chromatic](https://github.com/d3/d3-scale-chromatic) for examples. + */ export function interpolateRgbBasis(colors: Array): ((t: number) => string); + +/** + * Returns a uniform nonrational B-spline interpolator through the specified array of colors, which are converted to RGB color space. + * The control points are implicitly repeated such that the resulting spline has cyclical C² continuity when repeated around `t` in [0,1]; + * this is useful, for example, to create cyclical color scales. Opacity interpolation is not currently supported. + * See also `d3.interpolateBasisClosed, and see [d3-scale-chromatic](https://github.com/d3/d3-scale-chromatic) for examples. + */ export function interpolateRgbBasisClosed(colors: Array): ((t: number) => string); +/** + * Returns an HSL color space interpolator between the two colors *a* and *b*. The colors *a* and *b* need not be in HSL; + * they will be converted to HSL using `d3.hsl`. If either color’s hue or saturation is NaN, the opposing color’s channel value is used. + * The shortest path between hues is used. The return value of the interpolator is an RGB string. + */ export function interpolateHsl(a: string | ColorCommonInstance, b: string | ColorCommonInstance): ((t: number) => string); + +/** + * Like `interpolateHsl`, but does not use the shortest path between hues. + */ export function interpolateHslLong(a: string | ColorCommonInstance, b: string | ColorCommonInstance): ((t: number) => string); + +/** + * Returns a Lab color space interpolator between the two colors *a* and *b*. The colors *a* and *b* need not be in Lab; + * they will be converted to Lab using `d3.lab`. The return value of the interpolator is an RGB string. + */ export function interpolateLab(a: string | ColorCommonInstance, b: string | ColorCommonInstance): ((t: number) => string); + +/** + * Returns an HCL color space interpolator between the two colors `a` and `b`. The colors `a` and `b` need not be in HCL; + * they will be converted to HCL using `d3.hcl`. If either color’s hue or chroma is NaN, the opposing color’s channel value is used. + * The shortest path between hues is used. The return value of the interpolator is an RGB string. + */ export function interpolateHcl(a: string | ColorCommonInstance, b: string | ColorCommonInstance): ((t: number) => string); + +/** + * Like `interpolateHcl`, but does not use the shortest path between hues. + */ export function interpolateHclLong(a: string | ColorCommonInstance, b: string | ColorCommonInstance): ((t: number) => string); + +/** + * Returns a Cubehelix color space interpolator between the two colors `a` and `b` using a configurable `gamma`. + * If the gamma is not specified, it defaults to 1.0. The colors `a` and `b` need not be in Cubehelix; + * they will be converted to Cubehelix using [`d3.cubehelix`](https://github.com/d3/d3-color#cubehelix). + * If either color’s hue or saturation is NaN, the opposing color’s channel value is used. The shortest path between hues is used. The return value of the interpolator is an RGB string. + */ export const interpolateCubehelix: ColorGammaInterpolationFactory; + +/** + * Like `interpolateCubehelix`, but does not use the shortest path between hues. + */ export const interpolateCubehelixLong: ColorGammaInterpolationFactory; -// Spline related +/** + * Returns an interpolator between the two hue angles `a` and `b`. If either hue is NaN, the opposing value is used. + * The shortest path between hues is used. The return value of the interpolator is a number in `[0, 360)`. + */ +export function interpolateHue(a: number, b: number): ((t: number) => number); +// Splines ------------------------------------------------------------------- + +/** + * Returns a uniform nonrational B-spline interpolator through the specified array of `values`, which must be numbers. + * Implicit control points are generated such that the interpolator returns `values[0]` at `t` = 0 and `values[values.length - 1]` at `t` = 1. + * See also [`d3.curveBasis`](https://github.com/d3/d3-shape#curveBasis). + */ export function interpolateBasis(splineNodes: number[]): ((t: number) => number); + +/** + * Returns a uniform nonrational B-spline interpolator through the specified array of `values`, which must be numbers. + * The control points are implicitly repeated such that the resulting one-dimensional spline has cyclical C² continuity when repeated around `t` in [0,1]. + * See also [`d3.curveBasisClosed`](https://github.com/d3/d3-shape#curveBasisClosed). + */ export function interpolateBasisClosed(splineNodes: number[]): ((t: number) => number); +// Piecewise ----------------------------------------------------------------- + +/** + * Returns a piecewise zoom interpolator, composing zoom interpolators for each adjacent pair of zoom view. + * The returned interpolator maps `t` in `[0, 1 / (n - 1)]` to `interpolate(values[0], values[1])`, `t` in `[1 / (n - 1), 2 / (n - 1)]` to `interpolate(values[1], values[2])`, + * and so on, where `n = values.length`. In effect, this is a lightweight linear scale. + * For example, to blend through three different zoom views: `d3.piecewise(d3.interpolateZoom, [[0, 0, 1], [0, 0, 10], [0, 0, 15]])`. + */ export function piecewise(interpolate: (a: ZoomView, b: ZoomView) => ZoomInterpolator, values: ZoomView[]): ZoomInterpolator; -export function piecewise(interpolate: (a: any[], b: A) => ArrayInterpolator, values: A): ArrayInterpolator; + +/** + * Returns a piecewise array interpolator, composing array interpolators for each adjacent pair of arrays. + * The returned interpolator maps `t` in `[0, 1 / (n - 1)]` to `interpolate(values[0], values[1])`, `t` in `[1 / (n - 1), 2 / (n - 1)]` to `interpolate(values[1], values[2])`, + * and so on, where `n = values.length`. In effect, this is a lightweight linear scale. + * For example, to blend through three different arrays: `d3.piecewise(d3.interpolateArray, [[0, 0, 1], [0, 0, 10], [0, 0, 15]])`. + */ +export function piecewise(interpolate: (a: any[], b: A) => ArrayInterpolator, values: A[]): ArrayInterpolator; + +/** + * Returns a piecewise interpolator, composing interpolators for each adjacent pair of values. + * The returned interpolator maps `t` in `[0, 1 / (n - 1)]` to `interpolate(values[0], values[1])`, `t` in `[1 / (n - 1), 2 / (n - 1)]` to `interpolate(values[1], values[2])`, + * and so on, where `n = values.length`. In effect, this is a lightweight linear scale. + * For example, to blend through red, green and blue: `d3.piecewise(d3.interpolateRgb.gamma(2.2), ["red", "green", "blue"])`. + */ export function piecewise(interpolate: (a: TData, b: TData) => Interpolator, values: TData[]): (t: number) => any; diff --git a/types/d3-interpolate/tsconfig.json b/types/d3-interpolate/tsconfig.json index 14435aff3d..53ba7f2e28 100644 --- a/types/d3-interpolate/tsconfig.json +++ b/types/d3-interpolate/tsconfig.json @@ -7,7 +7,7 @@ ], "noImplicitAny": true, "noImplicitThis": true, - "strictNullChecks": false, + "strictNullChecks": true, "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [ diff --git a/types/d3-interpolate/tslint.json b/types/d3-interpolate/tslint.json index 9846c79a4d..54efb0b84e 100644 --- a/types/d3-interpolate/tslint.json +++ b/types/d3-interpolate/tslint.json @@ -2,7 +2,6 @@ "extends": "dtslint/dt.json", "rules": { "unified-signatures": false, - "callable-types": false, "no-unnecessary-generics": false } } From f1be184576cd3a8469882c5085852c3256190664 Mon Sep 17 00:00:00 2001 From: denis Date: Mon, 17 Sep 2018 21:38:27 +0200 Subject: [PATCH 05/38] Dependency chain --- types/d3-array/index.d.ts | 1 + types/d3-axis/index.d.ts | 1 + types/d3-brush/index.d.ts | 1 + types/d3-chord/index.d.ts | 1 + types/d3-scale/index.d.ts | 1 + types/d3-scale/v1/index.d.ts | 1 + types/d3-selection-multi/index.d.ts | 1 + types/d3-transition/index.d.ts | 1 + types/d3-zoom/index.d.ts | 1 + 9 files changed, 9 insertions(+) diff --git a/types/d3-array/index.d.ts b/types/d3-array/index.d.ts index 67cd291f22..a42f8e1fe9 100644 --- a/types/d3-array/index.d.ts +++ b/types/d3-array/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/d3/d3-array // Definitions by: Alex Ford , Boris Yankov , Tom Wanzek // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 // Last module patch version validated against: 1.2.0 diff --git a/types/d3-axis/index.d.ts b/types/d3-axis/index.d.ts index ea67b74209..62d0503419 100644 --- a/types/d3-axis/index.d.ts +++ b/types/d3-axis/index.d.ts @@ -5,6 +5,7 @@ // Boris Yankov // denisname // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 // Last module patch version validated against: 1.0.8 diff --git a/types/d3-brush/index.d.ts b/types/d3-brush/index.d.ts index e3d11d8f11..0d558fe385 100644 --- a/types/d3-brush/index.d.ts +++ b/types/d3-brush/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/d3/d3-brush/ // Definitions by: Tom Wanzek , Alex Ford , Boris Yankov // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 // Last module patch version validated against: 1.0.3 diff --git a/types/d3-chord/index.d.ts b/types/d3-chord/index.d.ts index 176cfe7af8..80577f3528 100644 --- a/types/d3-chord/index.d.ts +++ b/types/d3-chord/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/d3/d3-chord/ // Definitions by: Tom Wanzek , Alex Ford , Boris Yankov // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 // Last module patch version validated against: 1.0.3 diff --git a/types/d3-scale/index.d.ts b/types/d3-scale/index.d.ts index 074cb69b95..cb6a0cf15e 100644 --- a/types/d3-scale/index.d.ts +++ b/types/d3-scale/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/d3/d3-scale/ // Definitions by: Tom Wanzek , Alex Ford , Boris Yankov // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 // Last module patch version validated against: 2.0.0 diff --git a/types/d3-scale/v1/index.d.ts b/types/d3-scale/v1/index.d.ts index 46fe6c2a12..acc5c1e964 100644 --- a/types/d3-scale/v1/index.d.ts +++ b/types/d3-scale/v1/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/d3/d3-scale/ // Definitions by: Tom Wanzek , Alex Ford , Boris Yankov // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 // Last module patch version validated against: 1.0.7 diff --git a/types/d3-selection-multi/index.d.ts b/types/d3-selection-multi/index.d.ts index 4dd2a47c46..6dedb2f5d0 100644 --- a/types/d3-selection-multi/index.d.ts +++ b/types/d3-selection-multi/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/d3/d3-selection-multi/ // Definitions by: Alex Ford , Boris Yankov // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 // Last module patch version validated against: 1.0.0 diff --git a/types/d3-transition/index.d.ts b/types/d3-transition/index.d.ts index 2f935802bb..4d166f6080 100644 --- a/types/d3-transition/index.d.ts +++ b/types/d3-transition/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/d3/d3-transition/ // Definitions by: Tom Wanzek , Alex Ford , Boris Yankov // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 // Last module patch version validated against: 1.1 diff --git a/types/d3-zoom/index.d.ts b/types/d3-zoom/index.d.ts index 5ba719d227..827390b871 100644 --- a/types/d3-zoom/index.d.ts +++ b/types/d3-zoom/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/d3/d3-zoom/ // Definitions by: Tom Wanzek , Alex Ford , Boris Yankov // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 // Last module patch version validated against: 1.7.0 From c470a2b80242380b4a2d36d164ec75070b0dee73 Mon Sep 17 00:00:00 2001 From: Simon Schick Date: Thu, 20 Sep 2018 18:59:56 +0200 Subject: [PATCH 06/38] Update index.d.ts --- types/shot/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/shot/index.d.ts b/types/shot/index.d.ts index 74661b57d9..3bf550d094 100644 --- a/types/shot/index.d.ts +++ b/types/shot/index.d.ts @@ -1,7 +1,7 @@ // Type definitions for shot 3.4 // Project: https://github.com/hapijs/shot -// Definitions by: AJP -// Simon Schick +// Definitions by: AJP +// Simon Schick // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 From 9dae9776ae5f04a7a477bd244992de11c9b2a46d Mon Sep 17 00:00:00 2001 From: Joey Silva Date: Thu, 20 Sep 2018 13:28:52 -0700 Subject: [PATCH 07/38] Update index.d.ts Make each option in options param of addLineWidgets optional. --- types/codemirror/index.d.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/types/codemirror/index.d.ts b/types/codemirror/index.d.ts index 729b8a86d7..a3b775ab5e 100644 --- a/types/codemirror/index.d.ts +++ b/types/codemirror/index.d.ts @@ -262,13 +262,13 @@ declare namespace CodeMirror { Note that the widget node will become a descendant of nodes with CodeMirror-specific CSS classes, and those classes might in some cases affect it. */ addLineWidget(line: any, node: HTMLElement, options?: { /** Whether the widget should cover the gutter. */ - coverGutter: boolean; + coverGutter?: boolean; /** Whether the widget should stay fixed in the face of horizontal scrolling. */ - noHScroll: boolean; + noHScroll?: boolean; /** Causes the widget to be placed above instead of below the text of the line. */ - above: boolean; + above?: boolean; /** When true, will cause the widget to be rendered even if the line it is associated with is hidden. */ - showIfHidden: boolean; + showIfHidden?: boolean; }): CodeMirror.LineWidget; From 85625b1f4f29df149e4622cd20c812b1ddd7cb1c Mon Sep 17 00:00:00 2001 From: Sean Kelley Date: Thu, 20 Sep 2018 14:03:59 -0700 Subject: [PATCH 08/38] Add list* props to Breadcrumb. --- types/reactstrap/lib/Breadcrumb.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/types/reactstrap/lib/Breadcrumb.d.ts b/types/reactstrap/lib/Breadcrumb.d.ts index 8cef634a53..9fd2385041 100644 --- a/types/reactstrap/lib/Breadcrumb.d.ts +++ b/types/reactstrap/lib/Breadcrumb.d.ts @@ -4,6 +4,8 @@ import { CSSModule } from '../index'; export type BreadcrumbProps = React.HTMLAttributes & { tag?: string; className?: string; + listTag?: string; + listClassName?: string; cssModule?: CSSModule; } & T; From 2086a14ba0898071f22295c438713fe4dbbfad26 Mon Sep 17 00:00:00 2001 From: Max Knor Date: Sat, 22 Sep 2018 11:04:18 +0200 Subject: [PATCH 09/38] Added declarations for MarkdownIt-Lazy-Headers project --- types/markdown-it-lazy-headers/index.d.ts | 11 +++++++++ .../markdown-it-lazyheaders-tests.ts | 13 +++++++++++ types/markdown-it-lazy-headers/tsconfig.json | 23 +++++++++++++++++++ types/markdown-it-lazy-headers/tslint.json | 1 + 4 files changed, 48 insertions(+) create mode 100644 types/markdown-it-lazy-headers/index.d.ts create mode 100644 types/markdown-it-lazy-headers/markdown-it-lazyheaders-tests.ts create mode 100644 types/markdown-it-lazy-headers/tsconfig.json create mode 100644 types/markdown-it-lazy-headers/tslint.json diff --git a/types/markdown-it-lazy-headers/index.d.ts b/types/markdown-it-lazy-headers/index.d.ts new file mode 100644 index 0000000000..cde0f0f315 --- /dev/null +++ b/types/markdown-it-lazy-headers/index.d.ts @@ -0,0 +1,11 @@ +// Type definitions for MarkdownItLazyHeaders (markdown-it-lazy-headers) 0.13 +// Project: https://github.com/Galadirith/markdown-it-lazy-headers +// Definitions by: Knom +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +import { MarkdownIt, Core, Token } from 'markdown-it'; + +declare function lazyheaders(md: MarkdownIt): void; + +export = lazyheaders; diff --git a/types/markdown-it-lazy-headers/markdown-it-lazyheaders-tests.ts b/types/markdown-it-lazy-headers/markdown-it-lazyheaders-tests.ts new file mode 100644 index 0000000000..27230bfe1b --- /dev/null +++ b/types/markdown-it-lazy-headers/markdown-it-lazyheaders-tests.ts @@ -0,0 +1,13 @@ +import * as MarkdownIt from "markdown-it"; +import lazyHeaders = require("markdown-it-lazy-headers"); + +const md = new MarkdownIt(); + +md.use(lazyHeaders); + +const src = `# First header +Lorem ipsum. +## Next section! +This is totaly awesome.`; + +md.render(src); diff --git a/types/markdown-it-lazy-headers/tsconfig.json b/types/markdown-it-lazy-headers/tsconfig.json new file mode 100644 index 0000000000..353603784a --- /dev/null +++ b/types/markdown-it-lazy-headers/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "markdown-it-lazyheaders-tests.ts" + ] +} \ No newline at end of file diff --git a/types/markdown-it-lazy-headers/tslint.json b/types/markdown-it-lazy-headers/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/markdown-it-lazy-headers/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From d68aa4bbc6daf72f1ce6d0c69f594cc9ea4e0ff0 Mon Sep 17 00:00:00 2001 From: Max Knor Date: Sat, 22 Sep 2018 11:23:48 +0200 Subject: [PATCH 10/38] Changed filename of tests.ts --- ...t-lazyheaders-tests.ts => markdown-it-lazy-headers-tests.ts} | 0 types/markdown-it-lazy-headers/tsconfig.json | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename types/markdown-it-lazy-headers/{markdown-it-lazyheaders-tests.ts => markdown-it-lazy-headers-tests.ts} (100%) diff --git a/types/markdown-it-lazy-headers/markdown-it-lazyheaders-tests.ts b/types/markdown-it-lazy-headers/markdown-it-lazy-headers-tests.ts similarity index 100% rename from types/markdown-it-lazy-headers/markdown-it-lazyheaders-tests.ts rename to types/markdown-it-lazy-headers/markdown-it-lazy-headers-tests.ts diff --git a/types/markdown-it-lazy-headers/tsconfig.json b/types/markdown-it-lazy-headers/tsconfig.json index 353603784a..96e39b5ffe 100644 --- a/types/markdown-it-lazy-headers/tsconfig.json +++ b/types/markdown-it-lazy-headers/tsconfig.json @@ -18,6 +18,6 @@ }, "files": [ "index.d.ts", - "markdown-it-lazyheaders-tests.ts" + "markdown-it-lazy-headers-tests.ts" ] } \ No newline at end of file From b9c03395c01ebc3475362db060df405f1c051fa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joa=CC=83o=20Vieira?= Date: Mon, 24 Sep 2018 18:31:50 +0100 Subject: [PATCH 11/38] Update to Next.js 7. --- types/next/app.d.ts | 13 ++++-- types/next/config.d.ts | 2 +- types/next/document.d.ts | 58 ++++++++++++++++--------- types/next/error.d.ts | 14 +++++- types/next/head.d.ts | 2 +- types/next/index.d.ts | 19 +++----- types/next/link.d.ts | 10 +++-- types/next/router.d.ts | 23 +++++----- types/next/test/next-document-tests.tsx | 52 ++++++++-------------- types/next/test/next-error-tests.tsx | 19 +++++++- types/next/test/next-tests.ts | 2 - 11 files changed, 124 insertions(+), 90 deletions(-) diff --git a/types/next/app.d.ts b/types/next/app.d.ts index eea2af428b..2d6e79faa1 100644 --- a/types/next/app.d.ts +++ b/types/next/app.d.ts @@ -19,6 +19,14 @@ export interface NextAppContext { ctx: NextContext; } +/** + * Initial Props returned from base App class. + * https://github.com/zeit/next.js/blob/7.0.0/lib/app.js#L16 + */ +export interface DefaultAppIProps { + pageProps: any; +} + /** * Props passed to the App component. * Component and pageProps are dynamic - cannot infer type. @@ -28,7 +36,6 @@ export interface NextAppContext { export interface AppProps { Component: NextComponentType>; router: RouterProps; - pageProps: any; } /** @@ -41,6 +48,6 @@ export interface AppProps { export type AppComponentType = NextComponentType; export class Container extends React.Component {} -export default class App

extends React.Component

{ - static getInitialProps(context: NextAppContext): Promise<{ pageProps: any }>; +export default class App

extends React.Component

{ + static getInitialProps(context: NextAppContext): Promise; } diff --git a/types/next/config.d.ts b/types/next/config.d.ts index 1b2e330bb0..8466b60a4f 100644 --- a/types/next/config.d.ts +++ b/types/next/config.d.ts @@ -1 +1 @@ -export default function(): {serverRuntimeConfig: any, publicRuntimeConfig: any}; +export default function(): { serverRuntimeConfig: any; publicRuntimeConfig: any }; diff --git a/types/next/document.d.ts b/types/next/document.d.ts index 8296a8f136..febd36eb4a 100644 --- a/types/next/document.d.ts +++ b/types/next/document.d.ts @@ -3,14 +3,9 @@ import { NextContext, NextComponentType } from "."; import { DefaultQuery } from "./router"; export interface RenderPageResponse { - buildManifest: { [key: string]: any }; - chunks: { - names: string[]; - filenames: string[]; - }; + buildManifest: Record; html?: string; - head: Array>; - errorHtml: string; + head?: Array>; } export interface PageProps { @@ -38,24 +33,42 @@ export interface NextDocumentContext exte } /** - * Props passed to the Document component. + * Initial Props returned from base Document class. + * https://github.com/zeit/next.js/blob/7.0.0/server/document.js#L16 */ -export interface DocumentProps { - __NEXT_DATA__?: any; - dev?: boolean; - chunks?: { - names: string[]; - filenames: string[]; - }; - html?: string; - head?: Array>; - errorHtml?: string; +export interface DefaultDocumentIProps extends RenderPageResponse { styles?: Array>; - [key: string]: any; +} + +/** + * Props passed to the Document component. + * https://github.com/zeit/next.js/blob/7.0.0/server/render.js#L165 + */ +export interface DocumentProps { + __NEXT_DATA__: { + props: any; + page: string; + pathname: string; + query: Q; + buildId: string; + assetPrefix?: string; + runtimeConfig?: any; + nextExport?: boolean; + err?: any; + }; + dev: boolean; + dir?: string; + staticMarkup: boolean; + buildManifest: Record; + devFiles: string[]; + files: string[]; + dynamicImports: string[]; + assetPrefix: string; } /** * Props supported by the Head component. + * https://github.com/zeit/next.js/blob/7.0.0/server/document.js#L42 */ export interface HeadProps { nonce?: string; @@ -64,6 +77,7 @@ export interface HeadProps { /** * Props supported by the NextScript component. + * https://github.com/zeit/next.js/blob/7.0.0/server/document.js#L141 */ export interface NextScriptProps { nonce?: string; @@ -86,6 +100,8 @@ export type DocumentComponentType = NextCompon export class Head extends React.Component {} export class Main extends React.Component {} export class NextScript extends React.Component {} -export default class Document

extends React.Component

{ - static getInitialProps(context: NextDocumentContext): DocumentProps; +export default class Document

extends React.Component< + P & DefaultDocumentIProps & DocumentProps +> { + static getInitialProps(context: NextDocumentContext): DefaultDocumentIProps; } diff --git a/types/next/error.d.ts b/types/next/error.d.ts index d05d25b9c8..09d7e31860 100644 --- a/types/next/error.d.ts +++ b/types/next/error.d.ts @@ -1,2 +1,14 @@ import * as React from "react"; -export default class extends React.Component<{ statusCode: number }> {} +import { NextContext } from "."; + +/** + * Initial props returned from base Error class. + * https://github.com/zeit/next.js/blob/7.0.0/lib/error.js#L7 + */ +export interface DefaultErrorIProps { + statusCode: number; +} + +export default class Error

extends React.Component

{ + static getInitialProps(context: NextContext): DefaultErrorIProps; +} diff --git a/types/next/head.d.ts b/types/next/head.d.ts index 24fab7a076..d46b371d11 100644 --- a/types/next/head.d.ts +++ b/types/next/head.d.ts @@ -1,7 +1,7 @@ import * as React from "react"; export function defaultHead(): JSX.Element[]; -export default class extends React.Component { +export default class Head extends React.Component { static canUseDOM: boolean; static peek(): Array>; static rewind(): Array>; diff --git a/types/next/index.d.ts b/types/next/index.d.ts index f4b7affedd..16f3fb7f02 100644 --- a/types/next/index.d.ts +++ b/types/next/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for next 6.1 +// Type definitions for next 7.0 // Project: https://github.com/zeit/next.js // Definitions by: Drew Hays // Brice BERNARD @@ -16,7 +16,7 @@ import * as url from "url"; import { Response as NodeResponse } from "node-fetch"; -import { SingletonRouter, DefaultQuery } from "./router"; +import { SingletonRouter, DefaultQuery, UrlLike } from "./router"; declare namespace next { // Deprecated @@ -24,12 +24,10 @@ declare namespace next { type ServerConfig = NextConfig; // End Deprecated - type UrlLike = url.UrlObject | url.Url; - /** * Context object used in methods like `getInitialProps()` - * https://github.com/zeit/next.js/blob/6.1.1/server/render.js#L77 - * https://github.com/zeit/next.js/blob/6.1.1/readme.md#fetching-data-and-component-lifecycle + * https://github.com/zeit/next.js/blob/7.0.0/server/render.js#L97 + * https://github.com/zeit/next.js/blob/7.0.0/README.md#fetching-data-and-component-lifecycle * * @template Q Query object schema. */ @@ -52,7 +50,7 @@ declare namespace next { /** * Next.js config schema. - * https://github.com/zeit/next.js/blob/6.1.1/server/config.js#L10 + * https://github.com/zeit/next.js/blob/7.0.0/server/config.js#L9 */ interface NextConfig { webpack?: any; @@ -74,7 +72,7 @@ declare namespace next { /** * Options passed to the Server constructor in Node.js. - * https://github.com/zeit/next.js/blob/6.1.1/server/index.js#L30 + * https://github.com/zeit/next.js/blob/7.0.0/server/index.js#L25 */ interface ServerOptions { dir?: string; @@ -89,7 +87,7 @@ declare namespace next { */ interface Server { // From constructor - // https://github.com/zeit/next.js/blob/6.1.1/server/index.js#L30 + // https://github.com/zeit/next.js/blob/7.0.0/server/index.js#L25 dir: string; dev: boolean; quiet: boolean; @@ -105,7 +103,6 @@ declare namespace next { distDir: string; hotReloader: any; buildId: string; - availableChunks: object; generateETags: boolean; runtimeConfig?: object; }; @@ -172,9 +169,7 @@ declare namespace next { ): Promise; isServeableUrl(path: string): boolean; readBuildId(): string; - handleBuildId(buildId: string, res: http.ServerResponse): boolean; getCompilationError(): Promise; - send404(res: http.ServerResponse): void; } /** diff --git a/types/next/link.d.ts b/types/next/link.d.ts index 36c2e33546..12e3ee5419 100644 --- a/types/next/link.d.ts +++ b/types/next/link.d.ts @@ -1,8 +1,12 @@ import * as url from "url"; import * as React from "react"; +import { UrlLike } from "./router"; -export type UrlLike = url.UrlObject | url.Url; -export interface LinkState { +// Deprecated +export type LinkState = LinkProps; +// End Deprecated + +export interface LinkProps { prefetch?: boolean; shallow?: boolean; scroll?: boolean; @@ -14,4 +18,4 @@ export interface LinkState { children: React.ReactElement; } -export default class extends React.Component {} +export default class Link extends React.Component {} diff --git a/types/next/router.d.ts b/types/next/router.d.ts index 2039b213f8..4232f356c9 100644 --- a/types/next/router.d.ts +++ b/types/next/router.d.ts @@ -1,14 +1,13 @@ import * as React from "react"; import * as url from "url"; -type UrlLike = url.UrlObject | url.Url; - -type EventName = 'routeChangeStart' - | 'routeChangeComplete' - | 'routeChangeError' - | 'beforeHistoryChange' - | 'hashChangeStart' - | 'hashChangeComplete'; +type EventName = + | "routeChangeStart" + | "routeChangeComplete" + | "routeChangeError" + | "beforeHistoryChange" + | "hashChangeStart" + | "hashChangeComplete"; interface RouteChangeError { cancelled: boolean; @@ -17,6 +16,8 @@ interface RouteChangeError { type EventHandler = (url: string) => any; type ErrorEventHandler = (err: RouteChangeError, url: string) => any; +export type UrlLike = url.UrlObject | url.Url; + export interface EventChangeOptions { shallow?: boolean; [key: string]: any; @@ -47,13 +48,13 @@ export interface RouterProps { push( url: string | UrlLike, as?: string | UrlLike, - options?: EventChangeOptions, + options?: EventChangeOptions ): Promise; reload(route: string): Promise; replace( url: string | UrlLike, as?: string | UrlLike, - options?: EventChangeOptions, + options?: EventChangeOptions ): Promise; // events (deprecated soonish) @@ -87,7 +88,7 @@ export interface WithRouterProps { // without defining props explicitly export function withRouter( // tslint:disable-next-line:no-unnecessary-generics - Component: React.ComponentType>, + Component: React.ComponentType> ): React.ComponentType; declare const Router: SingletonRouter; diff --git a/types/next/test/next-document-tests.tsx b/types/next/test/next-document-tests.tsx index 40f01adfef..c97201b6f4 100644 --- a/types/next/test/next-document-tests.tsx +++ b/types/next/test/next-document-tests.tsx @@ -1,47 +1,42 @@ -import Document, { DocumentProps, Enhancer, Head, Main, NextScript, NextDocumentContext, PageProps } from 'next/document'; +import Document, { Enhancer, Head, Main, NextScript, NextDocumentContext, PageProps } from 'next/document'; import * as React from "react"; -const basicResults = ( - - - - -

- - -); +interface WithUrlProps { + url: string; +} -const withNonce = ( - - - - -); - -class MyDoc extends Document { - static async getInitialProps({ renderPage }: NextDocumentContext) { +class MyDoc extends Document { + static getInitialProps({ req, renderPage }: NextDocumentContext) { // without callback const _page = renderPage(); // with callback const enhancer: Enhancer = (App) => (props) => (); - const { html, head, errorHtml, chunks, buildManifest } = renderPage(enhancer); + const { html, head, buildManifest } = renderPage(enhancer); - const style = {}; + const styles = [ +