Skip to content

Commit 1a208b1

Browse files
authored
🤖 Merge PR DefinitelyTyped#72319 node/fs: Remove null from len parameter in truncate-related functions by @y-hsgw
1 parent e8db015 commit 1a208b1

File tree

4 files changed

+36
-18
lines changed

4 files changed

+36
-18
lines changed

‎types/node/fs.d.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ declare module "fs" {
581581
* @since v0.8.6
582582
* @param [len=0]
583583
*/
584-
export function truncate(path: PathLike, len: number | undefined | null, callback: NoParamCallback): void;
584+
export function truncate(path: PathLike, len: number | undefined, callback: NoParamCallback): void;
585585
/**
586586
* Asynchronous truncate(2) - Truncate a file to a specified length.
587587
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
@@ -593,7 +593,7 @@ declare module "fs" {
593593
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
594594
* @param len If not specified, defaults to `0`.
595595
*/
596-
function __promisify__(path: PathLike, len?: number | null): Promise<void>;
596+
function __promisify__(path: PathLike, len?: number): Promise<void>;
597597
}
598598
/**
599599
* Truncates the file. Returns `undefined`. A file descriptor can also be
@@ -604,7 +604,7 @@ declare module "fs" {
604604
* @since v0.8.6
605605
* @param [len=0]
606606
*/
607-
export function truncateSync(path: PathLike, len?: number | null): void;
607+
export function truncateSync(path: PathLike, len?: number): void;
608608
/**
609609
* Truncates the file descriptor. No arguments other than a possible exception are
610610
* given to the completion callback.
@@ -648,7 +648,7 @@ declare module "fs" {
648648
* @since v0.8.6
649649
* @param [len=0]
650650
*/
651-
export function ftruncate(fd: number, len: number | undefined | null, callback: NoParamCallback): void;
651+
export function ftruncate(fd: number, len: number | undefined, callback: NoParamCallback): void;
652652
/**
653653
* Asynchronous ftruncate(2) - Truncate a file to a specified length.
654654
* @param fd A file descriptor.
@@ -660,7 +660,7 @@ declare module "fs" {
660660
* @param fd A file descriptor.
661661
* @param len If not specified, defaults to `0`.
662662
*/
663-
function __promisify__(fd: number, len?: number | null): Promise<void>;
663+
function __promisify__(fd: number, len?: number): Promise<void>;
664664
}
665665
/**
666666
* Truncates the file descriptor. Returns `undefined`.
@@ -670,7 +670,7 @@ declare module "fs" {
670670
* @since v0.8.6
671671
* @param [len=0]
672672
*/
673-
export function ftruncateSync(fd: number, len?: number | null): void;
673+
export function ftruncateSync(fd: number, len?: number): void;
674674
/**
675675
* Asynchronously changes owner and group of a file. No arguments other than a
676676
* possible exception are given to the completion callback.

‎types/node/test/fs.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,24 @@ async function testPromisify() {
539539
});
540540
}
541541

542+
{
543+
fs.truncate("path/file.txt", () => {});
544+
fs.truncate("path/file.txt", 5, () => {});
545+
fs.truncate("path/file.txt", undefined, () => {});
546+
547+
fs.truncateSync("path/file.txt");
548+
fs.truncateSync("path/file.txt", 5);
549+
fs.truncateSync("path/file.txt", undefined);
550+
551+
fs.ftruncate(123, () => {});
552+
fs.ftruncate(123, 5, () => {});
553+
fs.ftruncate(123, undefined, () => {});
554+
555+
fs.ftruncateSync(123);
556+
fs.ftruncateSync(123, 5);
557+
fs.ftruncateSync(123, undefined);
558+
}
559+
542560
(async () => {
543561
const handle: FileHandle = await openAsync("test", "r");
544562
const writeStream = fs.createWriteStream("./index.d.ts", {

‎types/node/v18/fs.d.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ declare module "fs" {
609609
* @since v0.8.6
610610
* @param [len=0]
611611
*/
612-
export function truncate(path: PathLike, len: number | undefined | null, callback: NoParamCallback): void;
612+
export function truncate(path: PathLike, len: number | undefined, callback: NoParamCallback): void;
613613
/**
614614
* Asynchronous truncate(2) - Truncate a file to a specified length.
615615
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
@@ -621,7 +621,7 @@ declare module "fs" {
621621
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
622622
* @param len If not specified, defaults to `0`.
623623
*/
624-
function __promisify__(path: PathLike, len?: number | null): Promise<void>;
624+
function __promisify__(path: PathLike, len?: number): Promise<void>;
625625
}
626626
/**
627627
* Truncates the file. Returns `undefined`. A file descriptor can also be
@@ -632,7 +632,7 @@ declare module "fs" {
632632
* @since v0.8.6
633633
* @param [len=0]
634634
*/
635-
export function truncateSync(path: PathLike, len?: number | null): void;
635+
export function truncateSync(path: PathLike, len?: number): void;
636636
/**
637637
* Truncates the file descriptor. No arguments other than a possible exception are
638638
* given to the completion callback.
@@ -676,7 +676,7 @@ declare module "fs" {
676676
* @since v0.8.6
677677
* @param [len=0]
678678
*/
679-
export function ftruncate(fd: number, len: number | undefined | null, callback: NoParamCallback): void;
679+
export function ftruncate(fd: number, len: number | undefined, callback: NoParamCallback): void;
680680
/**
681681
* Asynchronous ftruncate(2) - Truncate a file to a specified length.
682682
* @param fd A file descriptor.
@@ -688,7 +688,7 @@ declare module "fs" {
688688
* @param fd A file descriptor.
689689
* @param len If not specified, defaults to `0`.
690690
*/
691-
function __promisify__(fd: number, len?: number | null): Promise<void>;
691+
function __promisify__(fd: number, len?: number): Promise<void>;
692692
}
693693
/**
694694
* Truncates the file descriptor. Returns `undefined`.
@@ -698,7 +698,7 @@ declare module "fs" {
698698
* @since v0.8.6
699699
* @param [len=0]
700700
*/
701-
export function ftruncateSync(fd: number, len?: number | null): void;
701+
export function ftruncateSync(fd: number, len?: number): void;
702702
/**
703703
* Asynchronously changes owner and group of a file. No arguments other than a
704704
* possible exception are given to the completion callback.

‎types/node/v20/fs.d.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ declare module "fs" {
579579
* @since v0.8.6
580580
* @param [len=0]
581581
*/
582-
export function truncate(path: PathLike, len: number | undefined | null, callback: NoParamCallback): void;
582+
export function truncate(path: PathLike, len: number | undefined, callback: NoParamCallback): void;
583583
/**
584584
* Asynchronous truncate(2) - Truncate a file to a specified length.
585585
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
@@ -591,7 +591,7 @@ declare module "fs" {
591591
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
592592
* @param len If not specified, defaults to `0`.
593593
*/
594-
function __promisify__(path: PathLike, len?: number | null): Promise<void>;
594+
function __promisify__(path: PathLike, len?: number): Promise<void>;
595595
}
596596
/**
597597
* Truncates the file. Returns `undefined`. A file descriptor can also be
@@ -602,7 +602,7 @@ declare module "fs" {
602602
* @since v0.8.6
603603
* @param [len=0]
604604
*/
605-
export function truncateSync(path: PathLike, len?: number | null): void;
605+
export function truncateSync(path: PathLike, len?: number): void;
606606
/**
607607
* Truncates the file descriptor. No arguments other than a possible exception are
608608
* given to the completion callback.
@@ -646,7 +646,7 @@ declare module "fs" {
646646
* @since v0.8.6
647647
* @param [len=0]
648648
*/
649-
export function ftruncate(fd: number, len: number | undefined | null, callback: NoParamCallback): void;
649+
export function ftruncate(fd: number, len: number | undefined, callback: NoParamCallback): void;
650650
/**
651651
* Asynchronous ftruncate(2) - Truncate a file to a specified length.
652652
* @param fd A file descriptor.
@@ -658,7 +658,7 @@ declare module "fs" {
658658
* @param fd A file descriptor.
659659
* @param len If not specified, defaults to `0`.
660660
*/
661-
function __promisify__(fd: number, len?: number | null): Promise<void>;
661+
function __promisify__(fd: number, len?: number): Promise<void>;
662662
}
663663
/**
664664
* Truncates the file descriptor. Returns `undefined`.
@@ -668,7 +668,7 @@ declare module "fs" {
668668
* @since v0.8.6
669669
* @param [len=0]
670670
*/
671-
export function ftruncateSync(fd: number, len?: number | null): void;
671+
export function ftruncateSync(fd: number, len?: number): void;
672672
/**
673673
* Asynchronously changes owner and group of a file. No arguments other than a
674674
* possible exception are given to the completion callback.

0 commit comments

Comments
 (0)