From a1e32e69642cd3ca0f7a80946412e138d5649982 Mon Sep 17 00:00:00 2001 From: Hugues Stefanski Date: Mon, 29 Jan 2018 21:23:56 +0100 Subject: [PATCH] Strong typings of parsing methods --- types/d3-fetch/index.d.ts | 55 +++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/types/d3-fetch/index.d.ts b/types/d3-fetch/index.d.ts index f46a779003..6a62630808 100644 --- a/types/d3-fetch/index.d.ts +++ b/types/d3-fetch/index.d.ts @@ -3,45 +3,62 @@ // Definitions by: Hugues Stefanski // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +import { DSVParsedArray, DSVRowString, DSVRowAny } from 'd3-dsv'; + /**Fetches the binary file at the specified input URL as a Blob. */ -export function blob(input: string): Promise; +export function blob(url: string): Promise; /**Fetches the binary file at the specified input URL as a Blob. Passes init along to the underlying call to fetch. */ -export function blob(input: string, init: RequestInit): Promise; +export function blob(url: string, init: RequestInit): Promise; /**Fetches the binary file at the specified input URL as an ArrayBuffer. */ -export function buffer(input: string): Promise; +export function buffer(url: string): Promise; /**Fetches the binary file at the specified input URL as an ArrayBuffer. Passes init along to the underlying call to fetch. */ -export function buffer(input: string, init: RequestInit): Promise; +export function buffer(url: string, init: RequestInit): Promise; /**Equivalent to d3.dsv with the comma character as the delimiter. */ -export function csv(input: string): Promise; +export function csv(url: string): Promise>; /**Equivalent to d3.dsv with the comma character as the delimiter. */ -export function csv(input: string, init: RequestInit): Promise; +export function csv(url: string, init: RequestInit): Promise>; /**Equivalent to d3.dsv with the comma character as the delimiter. */ -export function csv(input: string, init: RequestInit, row: (d: any) => any): Promise; +export function csv( + url: string, + init: RequestInit, + row: (d: DSVRowAny) => ParsedRow +): Promise>; /**Fetches the DSV file at the specified input URL. */ -export function dsv(delimiter: string, input: string): Promise; -export function dsv(delimiter: string, input: string, init: RequestInit): Promise; -export function dsv(delimiter: string, input: string, init: RequestInit, row: any): Promise; +export function dsv(delimiter: string, url: string): Promise>; +/**Fetches the DSV file at the specified input URL. */ +export function dsv(delimiter: string, url: string, init: RequestInit): Promise>; +/**Fetches the DSV file at the specified input URL. */ +export function dsv( + delimiter: string, + url: string, + init: RequestInit, + row: (d: DSVRowAny) => ParsedRow +): Promise>; /**Fetches the image at the specified input URL. */ -export function image(input: string): Promise; +export function image(url: string): Promise; /**Fetches the image at the specified input URL. Passes init along to the underlying call to fetch. */ -export function image(input: string, init: RequestInit): Promise; +export function image(url: string, init: RequestInit): Promise; /**Fetches the json file at the specified input URL. */ -export function json(input: string): Promise; +export function json(url: string): Promise; /**Fetches the json file at the specified input URL. Passes init along to the underlying call to fetch. */ -export function json(input: string, init: RequestInit): Promise; +export function json(url: string, init: RequestInit): Promise; /**Fetches the text file at the specified input URL. */ -export function text(input: string): Promise; +export function text(url: string): Promise; /**Fetches the text file at the specified input URL. Passes init along to the underlying call to fetch. */ -export function text(input: string, init: RequestInit): Promise; +export function text(url: string, init: RequestInit): Promise; /**Equivalent to d3.dsv with the tab character as the delimiter. */ -export function tsv(input: string): Promise; +export function tsv(url: string): Promise>; /**Equivalent to d3.dsv with the tab character as the delimiter. */ -export function tsv(input: string, init: RequestInit): Promise; +export function tsv(url: string, init: RequestInit): Promise>; /**Equivalent to d3.dsv with the tab character as the delimiter. */ -export function tsv(input: string, init: RequestInit, row: (d: any) => any): Promise; +export function tsv( + url: string, + init: RequestInit, + row: (d: DSVRowAny) => ParsedRow +): Promise>;