Skip to content

Commit 21cbeed

Browse files
committed
feat(io): improve lines type
1 parent 66d9f44 commit 21cbeed

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

core/io.d.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,12 @@ declare namespace io {
3636
*
3737
* In case of errors this function raises the error, instead of returning an error code.
3838
*/
39-
function lines(): () => string;
4039
function lines<T extends FileReadFormat[]>(
41-
filename: string,
40+
filename?: string,
4241
...formats: T
43-
): LuaTupleIterable<{ [P in keyof T]?: T[P] extends 'n' ? number : string }>;
42+
): LuaTupleIterable<
43+
[] extends T ? [string] : { [P in keyof T]: T[P] extends 'n' ? number : string }
44+
>;
4445

4546
/**
4647
* This function opens a file, in the mode specified in the string mode. In case of success, it returns a new file handle.
@@ -120,7 +121,9 @@ interface LuaFile {
120121
*/
121122
lines<T extends FileReadFormat[]>(
122123
...formats: T
123-
): LuaTupleIterable<{ [P in keyof T]?: T[P] extends 'n' ? number : string }>;
124+
): LuaTupleIterable<
125+
[] extends T ? [string] : { [P in keyof T]: T[P] extends 'n' ? number : string }
126+
>;
124127

125128
/**
126129
* Reads the file file, according to the given formats, which specify what to read. For each format, the function returns a string or a number with the characters read, or nil if it cannot read data with the specified format. (In this latter case, the function does not read subsequent formats.) When called without formats, it uses a default format that reads the next line (see below).

0 commit comments

Comments
 (0)