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; 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-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 } } 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 diff --git a/types/ember__application/index.d.ts b/types/ember__application/index.d.ts index b51fc3d0da..7518d41cdb 100644 --- a/types/ember__application/index.d.ts +++ b/types/ember__application/index.d.ts @@ -1,5 +1,5 @@ // Type definitions for @ember/application 3.0 -// Project: http://emberjs.com/ +// Project: https://emberjs.com/api/ember/3.4/modules/@ember%2Fapplication // Definitions by: Mike North // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 diff --git a/types/ember__array/index.d.ts b/types/ember__array/index.d.ts index 0fca48bfe7..882455da73 100644 --- a/types/ember__array/index.d.ts +++ b/types/ember__array/index.d.ts @@ -1,5 +1,5 @@ // Type definitions for @ember/array 3.0 -// Project: http://emberjs.com/ +// Project: https://emberjs.com/api/ember/3.4/modules/@ember%2Farray // Definitions by: Mike North // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 diff --git a/types/ember__component/index.d.ts b/types/ember__component/index.d.ts index 1afaa371cb..a5c54a7793 100644 --- a/types/ember__component/index.d.ts +++ b/types/ember__component/index.d.ts @@ -1,5 +1,5 @@ // Type definitions for @ember/component 3.0 -// Project: http://emberjs.com/ +// Project: https://emberjs.com/api/ember/3.4/modules/@ember%2Fcomponent // Definitions by: Mike North // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 diff --git a/types/ember__controller/index.d.ts b/types/ember__controller/index.d.ts index 9fd2672323..684c8b04e4 100644 --- a/types/ember__controller/index.d.ts +++ b/types/ember__controller/index.d.ts @@ -1,5 +1,5 @@ // Type definitions for @ember/controller 3.0 -// Project: http://emberjs.com/ +// Project: https://emberjs.com/api/ember/3.4/modules/@ember%2Fcontroller // Definitions by: Mike North // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 diff --git a/types/ember__debug/index.d.ts b/types/ember__debug/index.d.ts index 5bf709d044..c8ace3eafb 100644 --- a/types/ember__debug/index.d.ts +++ b/types/ember__debug/index.d.ts @@ -1,5 +1,5 @@ // Type definitions for @ember/debug 3.0 -// Project: http://emberjs.com/ +// Project: https://emberjs.com/api/ember/3.4/modules/@ember%2Fdebug // Definitions by: Mike North // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 diff --git a/types/ember__engine/index.d.ts b/types/ember__engine/index.d.ts index 314201689d..ddd2e1bfb3 100644 --- a/types/ember__engine/index.d.ts +++ b/types/ember__engine/index.d.ts @@ -1,5 +1,5 @@ // Type definitions for @ember/engine 3.0 -// Project: http://emberjs.com/ +// Project: https://emberjs.com/api/ember/3.4/modules/@ember%2Fengine // Definitions by: Mike North // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 diff --git a/types/ember__error/index.d.ts b/types/ember__error/index.d.ts index 3b3d2c5623..1526379547 100644 --- a/types/ember__error/index.d.ts +++ b/types/ember__error/index.d.ts @@ -1,5 +1,5 @@ // Type definitions for @ember/error 3.0 -// Project: http://emberjs.com/ +// Project: https://emberjs.com/api/ember/3.4/modules/@ember%2Ferror // Definitions by: Mike North // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 diff --git a/types/ember__object/index.d.ts b/types/ember__object/index.d.ts index 416c9a6135..f915bdc82a 100644 --- a/types/ember__object/index.d.ts +++ b/types/ember__object/index.d.ts @@ -1,5 +1,5 @@ // Type definitions for @ember/object 3.0 -// Project: http://emberjs.com/ +// Project: https://emberjs.com/api/ember/3.4/modules/@ember%2Fobject // Definitions by: Mike North // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 diff --git a/types/ember__polyfills/index.d.ts b/types/ember__polyfills/index.d.ts index 1bca6dbba4..3c408229dc 100644 --- a/types/ember__polyfills/index.d.ts +++ b/types/ember__polyfills/index.d.ts @@ -1,5 +1,5 @@ // Type definitions for @ember/polyfills 3.0 -// Project: http://emberjs.com/ +// Project: https://emberjs.com/api/ember/3.4/modules/@ember%2Fpolyfills // Definitions by: Mike North // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 diff --git a/types/ember__routing/index.d.ts b/types/ember__routing/index.d.ts index 8f5085c402..059ca512ae 100644 --- a/types/ember__routing/index.d.ts +++ b/types/ember__routing/index.d.ts @@ -1,5 +1,5 @@ // Type definitions for @ember/routing 3.0 -// Project: http://emberjs.com/ +// Project: https://emberjs.com/api/ember/3.4/modules/@ember%2Frouting // Definitions by: Mike North // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 diff --git a/types/ember__runloop/index.d.ts b/types/ember__runloop/index.d.ts index f1deeb9d17..b5fed6fdcb 100644 --- a/types/ember__runloop/index.d.ts +++ b/types/ember__runloop/index.d.ts @@ -1,5 +1,5 @@ // Type definitions for @ember/runloop 3.0 -// Project: http://emberjs.com/ +// Project: https://emberjs.com/api/ember/3.4/modules/@ember%2Frunloop // Definitions by: Mike North // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 diff --git a/types/ember__service/index.d.ts b/types/ember__service/index.d.ts index 4d89a87d01..20eb513f89 100644 --- a/types/ember__service/index.d.ts +++ b/types/ember__service/index.d.ts @@ -1,5 +1,5 @@ // Type definitions for @ember/service 3.0 -// Project: http://emberjs.com/ +// Project: https://emberjs.com/api/ember/3.4/modules/@ember%2Fservice // Definitions by: Mike North // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 diff --git a/types/ember__string/index.d.ts b/types/ember__string/index.d.ts index d000cfa443..8a2a46c022 100644 --- a/types/ember__string/index.d.ts +++ b/types/ember__string/index.d.ts @@ -1,5 +1,5 @@ // Type definitions for @ember/string 3.0 -// Project: http://emberjs.com/ +// Project: https://emberjs.com/api/ember/3.4/modules/@ember%2Fstring // Definitions by: Mike North // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 diff --git a/types/ember__test/index.d.ts b/types/ember__test/index.d.ts index b63f2d983e..350bb90897 100644 --- a/types/ember__test/index.d.ts +++ b/types/ember__test/index.d.ts @@ -1,5 +1,5 @@ // Type definitions for @ember/test 3.0 -// Project: http://emberjs.com/ +// Project: https://emberjs.com/api/ember/3.4/modules/@ember%2Ftest // Definitions by: Mike North // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 diff --git a/types/fastify-jwt/fastify-jwt-tests.ts b/types/fastify-jwt/fastify-jwt-tests.ts index 9015990b25..6b92026b04 100644 --- a/types/fastify-jwt/fastify-jwt-tests.ts +++ b/types/fastify-jwt/fastify-jwt-tests.ts @@ -1,34 +1,35 @@ import { IncomingMessage, Server, ServerResponse } from "http"; -import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify-jwt"; +import fastifyJwt = require("fastify-jwt"); +import fastify = require("fastify"); -const fastify: FastifyInstance = { - jwt: { - decode: (token, options) => { - return token; - }, - secret: "some-string", - sign: (payload, options) => { - return JSON.stringify(payload); - }, - verify: (token, options) => { - return token; - }, - }, -}; +const app = fastify(); -const req: FastifyRequest = { - jwtVerify: (_options) => { - return req; - }, -}; +app.register(fastifyJwt, { + secret: "super-secret" +}); -const res: FastifyReply = { - jwtSign: (_payload, _options, _next) => { - return res; - }, -}; +app.register(fastifyJwt, { + secret: (request, reply, callback) => { + return ""; + } +}); -fastify.jwt.sign({ a: "b" }, {}, (err, token) => { +app.get("/path", (request, reply) => { + request.jwtVerify(); + request.jwtVerify({}); + request.jwtVerify({}, () => "string"); + request.jwtVerify(() => "string", () => "string"); + + reply.jwtSign("payload"); + reply.jwtSign("payload", {}); + reply.jwtSign("payload", {}, () => "string"); + reply.jwtSign({ a: "b" }, {}, () => "string"); + reply.jwtSign([], {}, () => "string"); + reply.jwtSign(new Buffer("buffer"), {}, () => "string"); + reply.jwtSign("payload", () => "string", () => "string"); +}); + +app.jwt.sign({ a: "b" }, {}, (err, token) => { if (err) { throw err; } @@ -36,7 +37,7 @@ fastify.jwt.sign({ a: "b" }, {}, (err, token) => { return token; }); -fastify.jwt.sign("string", { algorithm: "some-algorithm" }, (err, token) => { +app.jwt.sign("string", { algorithm: "some-algorithm" }, (err, token) => { if (err) { throw err; } @@ -44,7 +45,7 @@ fastify.jwt.sign("string", { algorithm: "some-algorithm" }, (err, token) => { return token; }); -fastify.jwt.sign([], {}, (err, token) => { +app.jwt.sign([], {}, (err, token) => { if (err) { throw err; } @@ -52,7 +53,7 @@ fastify.jwt.sign([], {}, (err, token) => { return token; }); -fastify.jwt.sign(9999, {}, (err, token) => { +app.jwt.sign(new Buffer("buffer"), {}, (err, token) => { if (err) { throw err; } @@ -60,26 +61,13 @@ fastify.jwt.sign(9999, {}, (err, token) => { return token; }); -fastify.jwt.decode("some-token"); -fastify.jwt.decode("some-token"); -fastify.jwt.secret = "some-secret"; -fastify.jwt.verify("some-token", {}, (err) => { +app.jwt.decode("some-token"); +app.jwt.decode("some-token"); +app.jwt.secret = "some-secret"; +app.jwt.verify("some-token", {}, (err) => { if (err) { throw err; } return true; }); - -req.jwtVerify(); -req.jwtVerify({}); -req.jwtVerify({}, () => "string"); -req.jwtVerify(() => "string", () => "string"); - -res.jwtSign("payload"); -res.jwtSign("payload", {}); -res.jwtSign("payload", {}, () => "string"); -res.jwtSign({ a: "b" }, {}, () => "string"); -res.jwtSign([], {}, () => "string"); -res.jwtSign(9999, {}, () => "string"); -res.jwtSign("payload", () => "string", () => "string"); diff --git a/types/fastify-jwt/index.d.ts b/types/fastify-jwt/index.d.ts index 801a135f84..94e6249a3c 100644 --- a/types/fastify-jwt/index.d.ts +++ b/types/fastify-jwt/index.d.ts @@ -1,26 +1,52 @@ // Type definitions for fastify-jwt 0.4 // Project: https://github.com/fastify/fastify-jwt#readme -// Definitions by: My Self +// Definitions by: Jannik Keye // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 2.4 +import fastify = require("fastify"); import { Secret, SignOptions, VerifyOptions, VerifyCallback, SignCallback, DecodeOptions } from 'jsonwebtoken'; +import { IncomingMessage, ServerResponse } from 'http'; -export interface FastifyInstance { - jwt: jwt; +declare module "fastify" { + interface FastifyInstance { + jwt: jwt; + } + + interface SignFunction { + (payload: string | Buffer | object, options?: SignOptions): string; + (payload: string | Buffer | object, options?: SignOptions, callback?: SignCallback): void; + } + + interface VerifyFunction { + (token: string, options?: VerifyOptions, callback?: VerifyCallback): void; + (token: string, options?: VerifyOptions): object | string; + } + + interface jwt { + sign: SignFunction; + verify: VerifyFunction; + decode(token: string, options?: DecodeOptions): null | { [key: string]: any } | string; + secret: Secret; + } + + interface FastifyRequest { + jwtVerify: (options?: VerifyOptions | VerifyCallback, next?: VerifyCallback) => Promise | null | { [key: string]: any } | string; + } + + interface FastifyReply { + jwtSign: (payload: string | Buffer | object, options?: SignOptions | SignCallback, next?: SignCallback) => void; + } } -export interface jwt { - sign: (payload: any, options?: SignOptions, callback?: SignCallback) => void; - verify: (token: string, options?: VerifyOptions, callback?: VerifyCallback) => void; - decode: (token: string, options?: DecodeOptions) => null | { [key: string]: any } | string; - secret: Secret; +declare function fastifyJwt(): void; + +declare namespace fastifyJwt { + type SecretCallback = (request: fastify.FastifyRequest, reply: string | Buffer | object, callback?: VerifyCallback | SignCallback) => void; + + interface FastifyJwtOptions { + secret: string | SecretCallback; + } } -export interface FastifyRequest { - jwtVerify: (options?: VerifyOptions | VerifyCallback, next?: VerifyCallback) => Promise | null | { [key: string]: any } | string; -} - -export interface FastifyReply { - jwtSign: (payload: any, options?: SignOptions | SignCallback, next?: SignCallback) => void; -} +export = fastifyJwt; diff --git a/types/fastify-jwt/package.json b/types/fastify-jwt/package.json new file mode 100644 index 0000000000..948a91ff5b --- /dev/null +++ b/types/fastify-jwt/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "fastify": "^1.11.2" + } +} \ No newline at end of file diff --git a/types/ganache-core/ganache-core-tests.ts b/types/ganache-core/ganache-core-tests.ts index c0a6121c34..b58575277f 100644 --- a/types/ganache-core/ganache-core-tests.ts +++ b/types/ganache-core/ganache-core-tests.ts @@ -1,3 +1,3 @@ -import { provider } from "ganache-core"; +import { provider } from 'ganache-core'; -provider({ verbose: true }); +provider({ verbose: true, vmErrorsOnRPCResponse: false }); diff --git a/types/ganache-core/index.d.ts b/types/ganache-core/index.d.ts index 9297848806..07d0892f24 100644 --- a/types/ganache-core/index.d.ts +++ b/types/ganache-core/index.d.ts @@ -4,7 +4,7 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.4 -import { Provider } from "ethereum-protocol"; +import { Provider } from 'ethereum-protocol'; export interface GanacheOpts { verbose?: boolean; logger?: { @@ -15,5 +15,6 @@ export interface GanacheOpts { networkId?: number; mnemonic?: string; gasLimit?: number; + vmErrorsOnRPCResponse?: boolean; } export function provider(opts: GanacheOpts): Provider; diff --git a/types/hapi/index.d.ts b/types/hapi/index.d.ts index b152d34e5b..79732f3cfa 100644 --- a/types/hapi/index.d.ts +++ b/types/hapi/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for hapi 17.0 +// Type definitions for hapi 17.6 // Project: https://github.com/hapijs/hapi // Definitions by: Rafael Souza Fijalkowski // Justin Simms @@ -503,6 +503,14 @@ export interface Request extends Podium { */ readonly url: url.Url; + /** + * Returns `true` when the request is active and processing should continue and `false` when the + * request terminated early or completed its lifecycle. Useful when request processing is a + * resource-intensive operation and should be terminated early if the request is no longer active + * (e.g. client disconnected or aborted early). + */ + active(): boolean; + /** * Returns a response which you can pass into the reply interface where: * @param source - the value to set as the source of the reply interface, optional. @@ -1457,6 +1465,12 @@ export interface RouteOptionsResponse { status?: Util.Dictionary; } +/** + * @see https://www.w3.org/TR/referrer-policy/ + */ +export type ReferrerPolicy = '' | 'no-referrer' | 'no-referrer-when-downgrade' | 'unsafe-url' | + 'same-origin' | 'origin' | 'strict-origin' | 'origin-when-cross-origin' | 'strict-origin-when-cross-origin'; + /** * Default value: false (security headers disabled). * Sets common security headers. To enable, set security to true or to an object with the following options: @@ -1531,6 +1545,12 @@ export interface RouteOptionsSecureObject { * boolean controlling the 'X-Content-Type-Options' header. Defaults to true setting the header to its only and default option, 'nosniff'. */ noSniff?: boolean; + + /** + * Controls the `Referrer-Policy` header, which has the following possible values. + * @default false Header will not be send. + */ + referrer?: false | ReferrerPolicy; } export type RouteOptionsSecure = boolean | RouteOptionsSecureObject; @@ -1842,30 +1862,6 @@ export interface RouteOptions { /** * Default value: false (security headers disabled). - * Sets common security headers. To enable, set security to true or to an object with the following options: - * * hsts - controls the 'Strict-Transport-Security' header, where: - * * * true - the header will be set to max-age=15768000. This is the default value. - * * * a number - the maxAge parameter will be set to the provided value. - * * * an object with the following fields: - * * * * maxAge - the max-age portion of the header, as a number. Default is 15768000. - * * * * includeSubDomains - a boolean specifying whether to add the includeSubDomains flag to the header. - * * * * preload - a boolean specifying whether to add the 'preload' flag (used to submit domains inclusion in Chrome's HTTP Strict Transport Security (HSTS) preload list) to the header. - * * xframe - controls the 'X-Frame-Options' header, where: - * * * true - the header will be set to 'DENY'. This is the default value. - * * * 'deny' - the headers will be set to 'DENY'. - * * * 'sameorigin' - the headers will be set to 'SAMEORIGIN'. - * * * an object for specifying the 'allow-from' rule, where: - * * * * rule - one of: - * * * * * 'deny' - * * * * * 'sameorigin' - * * * * * 'allow-from' - * * * * source - when rule is 'allow-from' this is used to form the rest of the header, otherwise this field is ignored. If rule is 'allow-from' but source is unset, the rule will be - * automatically changed to 'sameorigin'. - * * xss - boolean that controls the 'X-XSS-PROTECTION' header for Internet Explorer. Defaults to true which sets the header to equal '1; mode=block'. - * Note: this setting can create a security vulnerability in versions of Internet Exploere below 8, as well as unpatched versions of IE8. See here and here for more information. If you - * actively support old versions of IE, it may be wise to explicitly set this flag to false. - * * noOpen - boolean controlling the 'X-Download-Options' header for Internet Explorer, preventing downloads from executing in your context. Defaults to true setting the header to 'noopen'. - * * noSniff - boolean controlling the 'X-Content-Type-Options' header. Defaults to true setting the header to its only and default option, 'nosniff'. * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionssecurity) */ security?: RouteOptionsSecure; @@ -2821,6 +2817,12 @@ export interface ServerOptions { load?: { /** the frequency of sampling in milliseconds. When set to 0, the other load options are ignored. Defaults to 0 (no sampling). */ sampleInterval?: number; + + /** + * Max concurrent requests. + */ + concurrent?: number; + /** maximum V8 heap size over which incoming requests are rejected with an HTTP Server Timeout (503) response. Defaults to 0 (no limit). */ maxHeapUsedBytes?: number; /** @@ -3177,7 +3179,9 @@ export interface ServerState { * An object containing the configuration of each cookie added via [server.state()](https://github.com/hapijs/hapi/blob/master/API.md#server.state()) where each key is the * cookie name and value is the configuration object. */ - readonly cookies: object; + readonly cookies: { + [key: string]: ServerStateCookieOptions; + }; /** * An array containing the names of all configued cookies. @@ -3232,6 +3236,8 @@ export type DecorationMethod = (this: T, ...args: any[]) => any; export interface PluginProperties { } +export type DecorateName = string | symbol; + /** * The server object is the main application container. The server manages all incoming requests along with all * the facilities provided by the framework. Each server supports a single connection (e.g. listen to port 80). @@ -3258,6 +3264,13 @@ export class Server extends Podium { */ auth: ServerAuth; + /** + * Links another server to the initialize/start/stop state of the current server by calling the + * controlled server `initialize()`/`start()`/`stop()` methods whenever the current server methods + * are called, where: + */ + control(server: Server): void; + /** * Provides access to the decorations already applied to various framework interfaces. The object must not be * modified directly, but only through server.decorate. @@ -3350,6 +3363,11 @@ export class Server extends Podium { * event loop delay milliseconds. */ eventLoopDelay: number; + + /** + * Max concurrent requests. + */ + concurrent: number /** * V8 heap usage. */ @@ -3473,14 +3491,14 @@ export class Server extends Podium { * @return void; * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverdecoratetype-property-method-options) */ - decorate(type: 'handler', property: string, method: HandlerDecorationMethod, options?: {apply?: boolean, extend?: boolean}): void; - decorate(type: 'request', property: string, method: (existing: ((...args: any[]) => any)) => (request: Request) => DecorationMethod, options: {apply: true, extend: true}): void; - decorate(type: 'request', property: string, method: (request: Request) => DecorationMethod, options: {apply: true, extend?: boolean}): void; - decorate(type: 'request', property: string, method: DecorationMethod, options?: {apply?: boolean, extend?: boolean}): void; - decorate(type: 'toolkit', property: string, method: (existing: ((...args: any[]) => any)) => DecorationMethod, options: {apply?: boolean, extend: true}): void; - decorate(type: 'toolkit', property: string, method: DecorationMethod, options?: {apply?: boolean, extend?: boolean}): void; - decorate(type: 'server', property: string, method: (existing: ((...args: any[]) => any)) => DecorationMethod, options: {apply?: boolean, extend: true}): void; - decorate(type: 'server', property: string, method: DecorationMethod, options?: {apply?: boolean, extend?: boolean}): void; + decorate(type: 'handler', property: DecorateName, method: HandlerDecorationMethod, options?: {apply?: boolean, extend?: boolean}): void; + decorate(type: 'request', property: DecorateName, method: (existing: ((...args: any[]) => any)) => (request: Request) => DecorationMethod, options: {apply: true, extend: true}): void; + decorate(type: 'request', property: DecorateName, method: (request: Request) => DecorationMethod, options: {apply: true, extend?: boolean}): void; + decorate(type: 'request', property: DecorateName, method: DecorationMethod, options?: {apply?: boolean, extend?: boolean}): void; + decorate(type: 'toolkit', property: DecorateName, method: (existing: ((...args: any[]) => any)) => DecorationMethod, options: {apply?: boolean, extend: true}): void; + decorate(type: 'toolkit', property: DecorateName, method: DecorationMethod, options?: {apply?: boolean, extend?: boolean}): void; + decorate(type: 'server', property: DecorateName, method: (existing: ((...args: any[]) => any)) => DecorationMethod, options: {apply?: boolean, extend: true}): void; + decorate(type: 'server', property: DecorateName, method: DecorationMethod, options?: {apply?: boolean, extend?: boolean}): void; /** * Used within a plugin to declare a required dependency on other plugins where: diff --git a/types/hapi/test/request/methods.ts b/types/hapi/test/request/methods.ts new file mode 100644 index 0000000000..cfe7db2383 --- /dev/null +++ b/types/hapi/test/request/methods.ts @@ -0,0 +1,4 @@ +import { Request } from 'hapi'; + +const req: Request = {}; +const act: boolean = req.active(); diff --git a/types/hapi/test/route/route-options.ts b/types/hapi/test/route/route-options.ts index d114154e60..438ef77d62 100644 --- a/types/hapi/test/route/route-options.ts +++ b/types/hapi/test/route/route-options.ts @@ -9,7 +9,8 @@ import { RouteOptionsPayload, RouteOptionsResponse, RouteOptionsValidate, - Server + Server, + RouteOptionsSecureObject } from "hapi"; const routeOptionsAccess: RouteOptionsAccess = { @@ -87,7 +88,20 @@ const routeOptionsResponse: RouteOptionsResponse = { 200: true, 302: true, 404: false, - } + }, +}; + +const routeOptionSecure: RouteOptionsSecureObject = { + referrer: 'origin', + noSniff: true, + xframe: "deny", + hsts: { + includeSubdomains: true, + maxAge: 1111, + preload: false, + }, + noOpen: false, + xss: true, }; const routeOptionsValidate: RouteOptionsValidate = { diff --git a/types/hapi/test/server/server-control.ts b/types/hapi/test/server/server-control.ts new file mode 100644 index 0000000000..8b145f1388 --- /dev/null +++ b/types/hapi/test/server/server-control.ts @@ -0,0 +1,3 @@ +import { Server } from "hapi"; + +new Server().control(new Server()); diff --git a/types/hapi/test/server/server-decorations.ts b/types/hapi/test/server/server-decorations.ts index c0ab94cc0e..7c060735a9 100644 --- a/types/hapi/test/server/server-decorations.ts +++ b/types/hapi/test/server/server-decorations.ts @@ -58,6 +58,8 @@ function decorateToolkitWithParams(this: ResponseToolkit, x: number, y: string) server.decorate('toolkit', 'withParams', decorateToolkitWithParams); +server.decorate('toolkit', Symbol('hi'), decorateToolkitWithParams); + server.route({ method: 'GET', path: '/toolkitWithParams', diff --git a/types/hapi/test/server/server-load.ts b/types/hapi/test/server/server-load.ts index d2ae11848a..8ac89fa006 100644 --- a/types/hapi/test/server/server-load.ts +++ b/types/hapi/test/server/server-load.ts @@ -3,7 +3,10 @@ import { Server } from "hapi"; const server = new Server({ port: 8000, - load: { sampleInterval: 1000 } + load: { + sampleInterval: 1000, + concurrent: 123, + } }); server.start(); diff --git a/types/hapi/tsconfig.json b/types/hapi/tsconfig.json index c93f0dfc7f..b197e3f861 100644 --- a/types/hapi/tsconfig.json +++ b/types/hapi/tsconfig.json @@ -21,32 +21,34 @@ "test/request/catch-all.ts", "test/request/event-types.ts", "test/request/get-log.ts", + "test/request/methods.ts", "test/request/parameters.ts", "test/request/query.ts", "test/response/continue.ts", "test/response/error.ts", "test/response/redirect.ts", - "test/response/response.ts", "test/response/response-events.ts", + "test/response/response.ts", "test/route/adding-routes.ts", "test/route/config.ts", - "test/route/handler.ts", "test/route/ext.ts", - "test/route/route-options.ts", + "test/route/handler.ts", "test/route/route-options-pre.ts", + "test/route/route-options.ts", "test/route/validation.ts", "test/server/server-app.ts", "test/server/server-auth-api.ts", "test/server/server-auth-default.ts", "test/server/server-auth-test.ts", "test/server/server-bind.ts", - "test/server/server-cache.ts", "test/server/server-cache-provision.ts", + "test/server/server-cache.ts", + "test/server/server-control.ts", "test/server/server-decoder.ts", "test/server/server-decorations.ts", "test/server/server-encoder.ts", - "test/server/server-events.ts", "test/server/server-events-once.ts", + "test/server/server-events.ts", "test/server/server-expose.ts", "test/server/server-info.ts", "test/server/server-inject.ts", diff --git a/types/joi/index.d.ts b/types/joi/index.d.ts index 166be7d526..2dd5c7f9e7 100644 --- a/types/joi/index.d.ts +++ b/types/joi/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for joi 13.4 +// Type definitions for joi 13.6 // Project: https://github.com/hapijs/joi // Definitions by: Bart van der Schoor // Laurence Dougal Myers @@ -197,6 +197,7 @@ export interface ReferenceOptions { functions?: boolean; } +// tslint:disable-next-line:interface-name export interface IPOptions { version?: string[]; cidr?: string; @@ -225,9 +226,7 @@ export interface ValidationErrorItem { context?: Context; } -export interface ValidationErrorFunction { - (errors: ValidationErrorItem[]): string | ValidationErrorItem | ValidationErrorItem[] | Error; -} +export type ValidationErrorFunction = (errors: ValidationErrorItem[]) => string | ValidationErrorItem | ValidationErrorItem[] | Error; export interface ValidationResult extends Pick, 'then' | 'catch'> { error: ValidationError; @@ -685,6 +684,11 @@ export interface StringSchema extends AnySchema { trim(): this; } +export interface SymbolSchema extends AnySchema { + // TODO: support number and symbol index + map(iterable: Iterable<[string | number | boolean | symbol, symbol]> | { [key: string]: symbol }): this; +} + export interface ArraySchema extends AnySchema { /** * Allow this array to be sparse. @@ -1078,6 +1082,11 @@ export function object(schema?: SchemaMap): ObjectSchema; */ export function string(): StringSchema; +/** + * Generates a schema object that matches any symbol. + */ +export function symbol(): SymbolSchema; + /** * Generates a type that will match one of the provided alternative schemas */ @@ -1110,7 +1119,6 @@ export function validate(value: T, schema: SchemaLike, options: Validation * Converts literal schema definition to joi schema object (or returns the same back if already a joi schema object). */ export function compile(schema: SchemaLike): Schema; -export function compile(schema: SchemaLike): T; /** * Validates a value against a schema and throws if validation fails. @@ -1145,9 +1153,7 @@ export function isRef(ref: any): ref is Reference; * of strings For string values path separator is a dot (`.`) */ export function reach(schema: ObjectSchema, path: string): Schema; -export function reach(schema: ObjectSchema, path: string): T; export function reach(schema: ObjectSchema, path: string[]): Schema; -export function reach(schema: ObjectSchema, path: string[]): T; /** * Creates a new Joi instance customized with the extension(s) you provide included. diff --git a/types/joi/joi-tests.ts b/types/joi/joi-tests.ts index c9805e1fc3..832858c7e9 100644 --- a/types/joi/joi-tests.ts +++ b/types/joi/joi-tests.ts @@ -1142,3 +1142,9 @@ schema = Joi.raw(bool); schema = Joi.empty(); schema = Joi.empty(str); schema = Joi.empty(anySchema); + +schema = Joi.symbol(); +schema = Joi.symbol().map(new Map()); +schema = Joi.symbol().map({ + key: Symbol('asd'), +}); diff --git a/types/joi/tslint.json b/types/joi/tslint.json index 87b70df769..c6e5f080fb 100644 --- a/types/joi/tslint.json +++ b/types/joi/tslint.json @@ -3,11 +3,8 @@ "rules": { // All are TODOs "ban-types": false, - "callable-types": false, - "interface-name": false, "no-empty-interface": false, "no-self-import": false, - "no-unnecessary-generics": false, "unified-signatures": false } } diff --git a/types/jquery/v2/index.d.ts b/types/jquery/v2/index.d.ts index 2f9a79adf4..15709d6357 100644 --- a/types/jquery/v2/index.d.ts +++ b/types/jquery/v2/index.d.ts @@ -3385,7 +3385,7 @@ interface JQuery { * @see {@link https://api.jquery.com/selector/} */ selector: string; - [index: number]: HTMLElement; + [index: number]: Element; /** * Add elements to the set of matched elements. 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..9eb8a54cf1 --- /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 } from 'markdown-it'; + +declare function lazyheaders(md: MarkdownIt): void; + +export = lazyheaders; diff --git a/types/markdown-it-lazy-headers/markdown-it-lazy-headers-tests.ts b/types/markdown-it-lazy-headers/markdown-it-lazy-headers-tests.ts new file mode 100644 index 0000000000..4957dbadf8 --- /dev/null +++ b/types/markdown-it-lazy-headers/markdown-it-lazy-headers-tests.ts @@ -0,0 +1,13 @@ +import MarkdownIt = require("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..96e39b5ffe --- /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-lazy-headers-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" } diff --git a/types/next/app.d.ts b/types/next/app.d.ts index eea2af428b..392b997f89 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,19 +36,23 @@ export interface NextAppContext { export interface AppProps { Component: NextComponentType>; router: RouterProps; - pageProps: any; } /** * App component type. Differs from the default type because the context it passes * to getInitialProps and the props is passes to the component are different. * + * @template P Component props. * @template IP Initial props returned from getInitialProps. * @template C Context passed to getInitialProps. */ -export type AppComponentType = NextComponentType; +export type AppComponentType

= NextComponentType< + P & AppProps, + IP, + C +>; 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..b76ed7b2b0 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; @@ -74,11 +88,12 @@ export interface NextScriptProps { * Document component type. Differs from the default type because the context it passes * to getInitialProps and the props is passes to the component are different. * + * @template P Component props. * @template IP Initial props returned from getInitialProps. * @template C Context passed to getInitialProps. */ -export type DocumentComponentType = NextComponentType< - IP & DocumentProps, +export type DocumentComponentType

= NextComponentType< + P & DocumentProps, IP, C >; @@ -86,6 +101,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/dynamic.d.ts b/types/next/dynamic.d.ts index 62d53f1e72..38a85bf77e 100644 --- a/types/next/dynamic.d.ts +++ b/types/next/dynamic.d.ts @@ -1,29 +1,42 @@ import * as React from "react"; +import { + LoadableComponent, + CommonOptions as LoadableOptions, + LoadingComponentProps as LoadableLoadingComponentProps +} from "react-loadable"; -export interface DynamicOptions { - loading?: React.ComponentType; +type Omit = Pick>; + +type AsyncComponent

= Promise>; +type AsyncComponentLoader

= () => AsyncComponent

; +type ModuleMapping = Record; +type LoadedModuleMapping = Record; + +interface NextDynamicOptions

extends Omit { + modules?: () => ModuleMapping; // overridden + loading?: LoadableOptions["loading"]; // optional + loader?: AsyncComponentLoader

; // optional, overriden + render?: (props: P, loaded: LoadedModuleMapping) => React.ReactNode; // optional, overriden ssr?: boolean; - modules?( - props: TCProps & TLProps, - ): { [key: string]: Promise> }; - render?( - props: TCProps & TLProps, - modules: { [key: string]: React.ComponentType }, - ): void; + loadableGenerated?: { + webpack?: any; + modules?: any; + }; } -export class SameLoopPromise extends Promise { - constructor( - executor: ( - resolve: (value?: T) => void, - reject: (reason?: any) => void, - ) => void, - ); - setResult(value: T): void; - setError(value: any): void; - runIfNeeded(): void; -} -export default function( - componentPromise: Promise>, - options?: DynamicOptions, -): React.ComponentType; +type DynamicComponent

= React.ComponentType

& LoadableComponent; + +/** + * Overloaded dynamic function. + * https://github.com/zeit/next.js/blob/7.0.0/lib/dynamic.js#L55 + */ +declare function dynamic

( + options: AsyncComponent

| NextDynamicOptions

+): DynamicComponent

; +declare function dynamic

( + asyncModule: AsyncComponent

, + options: NextDynamicOptions

+): DynamicComponent

; + +export type LoadingComponentProps = LoadableLoadingComponentProps; +export default dynamic; 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..d788ddd941 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 @@ -13,10 +13,8 @@ import * as http from "http"; 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 +22,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 +48,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 +70,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 +85,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 +101,6 @@ declare namespace next { distDir: string; hotReloader: any; buildId: string; - availableChunks: object; generateETags: boolean; runtimeConfig?: object; }; @@ -172,9 +167,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-app-tests.tsx b/types/next/test/next-app-tests.tsx index 8cf3e30655..eaa2c0ad07 100644 --- a/types/next/test/next-app-tests.tsx +++ b/types/next/test/next-app-tests.tsx @@ -2,8 +2,8 @@ import * as React from "react"; import App, { Container, NextAppContext, AppProps, AppComponentType } from "next/app"; import { DefaultQuery } from "next/router"; -interface NextComponentProps { - example: string; +interface TestAppProps { + pageProps: any; } interface TypedQuery extends DefaultQuery { @@ -21,10 +21,10 @@ class TestApp extends App { } } -class TestAppWithProps extends App { +class TestAppWithProps extends App { static async getInitialProps({ Component, router, ctx }: NextAppContext) { const pageProps = Component.getInitialProps && (await Component.getInitialProps(ctx)); - return { pageProps, example: "foobar" }; + return { pageProps }; } render() { @@ -55,8 +55,8 @@ interface TestProps { } // Stateful HOC that adds props to wrapped component. Similar to what withRedux does. -// tslint:disable-next-line no-unnecessary-generics -const withExample =

(App: AppComponentType

) => +// tslint:disable-next-line no-unnecessary-generics, use-default-type-parameter +const withExample =

(App: AppComponentType

) => class extends React.Component

{ test: string; @@ -79,7 +79,7 @@ const withExample =

(App: AppComponentType

) // Basic stateless HOC. Similar to what withAuth would do. // tslint:disable-next-line no-unnecessary-generics -const withBasic =

(App: AppComponentType) => +const withBasic =

(App: AppComponentType) => class extends React.Component

{ static async getInitialProps(context: C) { const pageProps = App.getInitialProps && (await App.getInitialProps(context)); diff --git a/types/next/test/next-document-tests.tsx b/types/next/test/next-document-tests.tsx index 40f01adfef..d25b340e64 100644 --- a/types/next/test/next-document-tests.tsx +++ b/types/next/test/next-document-tests.tsx @@ -1,47 +1,47 @@ -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 enhancer: Enhancer = App => props => ; + const { html, head, buildManifest } = renderPage(enhancer); - const style = {}; + const styles = [