diff --git a/packages/csv-generate/dist/cjs/index.d.cts b/packages/csv-generate/dist/cjs/index.d.cts index 581ed32f4..8e0931a87 100644 --- a/packages/csv-generate/dist/cjs/index.d.cts +++ b/packages/csv-generate/dist/cjs/index.d.cts @@ -5,6 +5,7 @@ import * as stream from "stream"; type Callback = (err?: Error, records?: unknown) => void; export class Generator extends stream.Readable { + end(): void; constructor(options?: Options); readonly options: Options; @@ -14,7 +15,9 @@ export type ColumnsFunctionArgs = { options: Options; state: State; }; -export type ColumnsFunction = (args: ColumnsFunctionArgs) => string; +export type ColumnsFunction = ( + args: ColumnsFunctionArgs, +) => string | number | null; export type State = { start_time: number; diff --git a/packages/csv-generate/dist/esm/index.d.ts b/packages/csv-generate/dist/esm/index.d.ts index 581ed32f4..8e0931a87 100644 --- a/packages/csv-generate/dist/esm/index.d.ts +++ b/packages/csv-generate/dist/esm/index.d.ts @@ -5,6 +5,7 @@ import * as stream from "stream"; type Callback = (err?: Error, records?: unknown) => void; export class Generator extends stream.Readable { + end(): void; constructor(options?: Options); readonly options: Options; @@ -14,7 +15,9 @@ export type ColumnsFunctionArgs = { options: Options; state: State; }; -export type ColumnsFunction = (args: ColumnsFunctionArgs) => string; +export type ColumnsFunction = ( + args: ColumnsFunctionArgs, +) => string | number | null; export type State = { start_time: number; diff --git a/packages/csv-generate/lib/index.d.ts b/packages/csv-generate/lib/index.d.ts index 581ed32f4..8e0931a87 100644 --- a/packages/csv-generate/lib/index.d.ts +++ b/packages/csv-generate/lib/index.d.ts @@ -5,6 +5,7 @@ import * as stream from "stream"; type Callback = (err?: Error, records?: unknown) => void; export class Generator extends stream.Readable { + end(): void; constructor(options?: Options); readonly options: Options; @@ -14,7 +15,9 @@ export type ColumnsFunctionArgs = { options: Options; state: State; }; -export type ColumnsFunction = (args: ColumnsFunctionArgs) => string; +export type ColumnsFunction = ( + args: ColumnsFunctionArgs, +) => string | number | null; export type State = { start_time: number; diff --git a/packages/csv-generate/test/options.columns.js b/packages/csv-generate/test/options.columns.ts similarity index 93% rename from packages/csv-generate/test/options.columns.js rename to packages/csv-generate/test/options.columns.ts index ab49d9aa4..1b00d7e26 100644 --- a/packages/csv-generate/test/options.columns.js +++ b/packages/csv-generate/test/options.columns.ts @@ -5,7 +5,7 @@ describe("Option `columns`", function () { it("as number", function (next) { this.timeout(1000000); let count = 0; - const data = []; + const data: Buffer[] = []; const generator = generate({ columns: 3 }); generator.on("readable", () => { let d; @@ -26,7 +26,7 @@ describe("Option `columns`", function () { it("as types", function (next) { this.timeout(1000000); let count = 0; - const data = []; + const data: Buffer[] = []; const generator = generate({ columns: ["int", "bool"], seed: 1 }); generator.on("readable", () => { let d; @@ -52,7 +52,7 @@ describe("Option `columns`", function () { try { generate({ columns: ["int", "bool", "invalid"] }); } catch (err) { - err.message.should.eql( + (err as Error).message.should.eql( 'Invalid column type: got "invalid", default values are ["ascii","int","bool"]', ); } @@ -61,7 +61,7 @@ describe("Option `columns`", function () { describe("user function", function () { it("accept string or null or number", function (next) { this.timeout(1000000); - const data = []; + const data: string[] = []; const generator = generate({ length: 1, columns: [() => "a", () => null, () => 1], @@ -81,6 +81,7 @@ describe("Option `columns`", function () { it("validate return argument", function (next) { this.timeout(1000000); + // @ts-expect-error Exercise runtime rejection of unsupported return values. const generator = generate({ objectMode: true, columns: [() => ({})], @@ -104,7 +105,7 @@ describe("Option `columns`", function () { it("validate arguments in objectMode", function (next) { this.timeout(1000000); - const data = []; + const data: unknown[] = []; const generator = generate({ objectMode: true, length: 1,