Skip to content

Commit b6363df

Browse files
committed
feat: make nil types in functions constistent
1 parent 0b9d65f commit b6363df

7 files changed

Lines changed: 26 additions & 19 deletions

File tree

core/debug.d.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ declare namespace debug {
8181
/**
8282
* Returns the metatable of the given value or nil if it does not have a metatable.
8383
*/
84-
function getmetatable<T extends any>(value: T): LuaMetatable<T> | null;
84+
function getmetatable<T extends any>(value: T): LuaMetatable<T> | undefined;
8585

8686
/**
8787
* Returns the registry table (see §4.5).
@@ -132,18 +132,23 @@ declare namespace debug {
132132
*
133133
* See debug.getlocal for more information about variable indices and names.
134134
*/
135-
function setlocal(level: number, local: number, value: any): string | null;
136-
function setlocal(thread: LuaThread, level: number, local: number, value: any): string | null;
135+
function setlocal(level: number, local: number, value: any): string | undefined;
136+
function setlocal(
137+
thread: LuaThread,
138+
level: number,
139+
local: number,
140+
value: any,
141+
): string | undefined;
137142

138143
/**
139144
* Sets the metatable for the given value to the given table (which can be nil). Returns value.
140145
*/
141-
function setmetatable<T>(value: T, table: LuaMetatable<T> | null): T;
146+
function setmetatable<T>(value: T, table: LuaMetatable<T> | null | undefined): T;
142147

143148
/**
144149
* This function assigns the value value to the upvalue with index up of the function f. The function returns nil if there is no upvalue with the given index. Otherwise, it returns the name of the upvalue.
145150
*/
146-
function setupvalue(f: Function, up: number, value: any): string | null;
151+
function setupvalue(f: Function, up: number, value: any): string | undefined;
147152

148153
/**
149154
* Sets the given value as the Lua value associated to the given udata. udata must be a full userdata.
@@ -155,6 +160,8 @@ declare namespace debug {
155160
/**
156161
* If message is present but is neither a string nor nil, this function returns message without further processing. Otherwise, it returns a string with a traceback of the call stack. The optional message string is appended at the beginning of the traceback. An optional level number tells at which level to start the traceback (default is 1, the function calling traceback).
157162
*/
158-
function traceback(thread?: LuaThread, message?: string | null, level?: number): string;
159-
function traceback<T>(thread?: LuaThread, message?: T, level?: number): T;
163+
function traceback(message?: string | null, level?: number | null): string;
164+
function traceback(thread?: LuaThread, message?: string | null, level?: number | null): string;
165+
function traceback<T>(message: T): T;
166+
function traceback<T>(thread: LuaThread, message: T): T;
160167
}

core/global.d.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ declare function error(message: string, level?: number): never;
7070
/**
7171
* If object does not have a metatable, returns nil. Otherwise, if the object's metatable has a __metatable field, returns the associated value. Otherwise, returns the metatable of the given object.
7272
*/
73-
declare function getmetatable<T extends object>(object: T): LuaMetatable<T> | null;
73+
declare function getmetatable<T extends object>(object: T): LuaMetatable<T> | undefined;
7474

7575
/**
7676
* Returns three values (an iterator function, the table t, and 0) so that the construction
@@ -157,7 +157,10 @@ declare function select<T>(index: '#', ...args: T[]): number;
157157
*
158158
* This function returns table.
159159
*/
160-
declare function setmetatable<T extends object>(table: T, metatable?: LuaMetatable<T>): T;
160+
declare function setmetatable<T extends object>(
161+
table: T,
162+
metatable: LuaMetatable<T> | null | undefined,
163+
): T;
161164

162165
/**
163166
* When called with no base, tonumber tries to convert its argument to a number. If the argument is already a number or a string convertible to a number, then tonumber returns this number; otherwise, it returns nil.
@@ -166,7 +169,7 @@ declare function setmetatable<T extends object>(table: T, metatable?: LuaMetatab
166169
*
167170
* When called with base, then e must be a string to be interpreted as an integer numeral in that base. The base may be any integer between 2 and 36, inclusive. In bases above 10, the letter 'A' (in either upper or lower case) represents 10, 'B' represents 11, and so forth, with 'Z' representing 35. If the string e is not a valid numeral in the given base, the function returns nil.
168171
*/
169-
declare function tonumber(e: any, base?: number): number | null;
172+
declare function tonumber(e: any, base?: number): number | undefined;
170173

171174
/**
172175
* Receives a value of any type and converts it to a string in a human-readable format. (For complete control of how numbers are converted, use string.format.)

core/io.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ interface LuaFile {
150150
* The default value for whence is "cur", and for offset is 0. Therefore, the call file:seek() returns the current file position, without changing it; the call file:seek("set") sets the position to the beginning of the file (and returns 0); and the call file:seek("end") sets the position to the end of the file, and returns its size.
151151
* @tupleReturn
152152
*/
153-
seek(whence?: 'set' | 'cur' | 'end', offset?: number): [number] | [null, string];
153+
seek(whence?: 'set' | 'cur' | 'end', offset?: number): [number] | [undefined, string];
154154

155155
/**
156156
* Sets the buffering mode for an output file. There are three available modes:

core/os.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ declare namespace os {
6969
/**
7070
* Returns the value of the process environment variable varname, or nil if the variable is not defined.
7171
*/
72-
function getenv(varname: string): string | null;
72+
function getenv(varname: string): string | undefined;
7373

7474
/**
7575
* Deletes the file (or empty directory, on POSIX systems) with the given name. If this function fails, it returns nil, plus a string describing the error and the error code. Otherwise, it returns true.
@@ -95,7 +95,7 @@ declare namespace os {
9595
function setlocale(
9696
locale?: string,
9797
category?: 'all' | 'collate' | 'ctype' | 'monetary' | 'numeric' | 'time',
98-
): string | null;
98+
): string | undefined;
9999

100100
/**
101101
* Returns the current time when called without arguments, or a time representing the local date and time specified by the given table. This table must have fields year, month, and day, and may have fields hour (default is 12), min (default is 0), sec (default is 0), and isdst (default is nil). Other fields are ignored. For a description of these fields, see the os.date function.

special/5.1-or-jit.d.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ declare namespace package {
7070
var loaders: (
7171
| (/** @tupleReturn */ (modname: string) => [(modname: string) => void])
7272
| (/** @tupleReturn */ <T>(modname: string) => [(modname: string, extra: T) => T, T])
73-
| string
74-
| undefined
75-
| null)[];
73+
| string)[];
7674
}
7775

7876
declare namespace os {

special/5.2-plus.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ declare namespace package {
4141
var searchers: (
4242
| (/** @tupleReturn */ (modname: string) => [(modname: string) => void])
4343
| (/** @tupleReturn */ <T>(modname: string) => [(modname: string, extra: T) => T, T])
44-
| string
45-
| undefined)[];
44+
| string)[];
4645
}
4746

4847
declare namespace table {

special/5.3-plus.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ declare namespace math {
3131
/**
3232
* Returns "integer" if x is an integer, "float" if it is a float, or nil if x is not a number.
3333
*/
34-
function type(x: number): 'integer' | 'float' | null;
34+
function type(x: number): 'integer' | 'float' | undefined;
3535

3636
/**
3737
* Returns a boolean, true if and only if integer m is below integer n when they are compared as unsigned integers.

0 commit comments

Comments
 (0)