Skip to content

Representing functions with a name that is a JavaScript reserved word #945

Description

@LoganDark

Currently I am using namespaces to represent Lua globals with functions inside of them- that is okay, but this is not okay:

/** @noSelf */
declare namespace fs {
	...

	/** Deletes a file or directory. */
	function delete(path: string): void // <---- delete is a reserved word that cannot be used here

	...
}

This is a problem - the function is named delete but TypeScript does not have the capability to represent this!

Merging is not allowed:

image

And even without type checking, the transpilation only recognizes the namespace declaration above so it doesn't even work correctly:

image

My only option is to include the function definition inside the namespace, but since function identifiers cannot be strings there is no way to name the function delete, so there needs to be a way to communicate to TypeScriptToLua that the function on the Lua side is named that way.

The issue? There isn't yet such a feature.

I propose an @luaName annotation, which will allow you to specify a Lua name for the function. This would allow me to name the function something different like _delete and then in the transpilation step it is turned back to delete.

Example:

/** @luaName bar */
declare function foo(x: string): void

foo('Hi!')

would transpile to

bar('Hi!')

Likewise,

/** @noSelf */
declare namespace fs {
	/** Deletes a file or directory.
	 * @luaName delete */
	function _delete(path: string): void
}

fs._delete('some path')

would transpile to

fs.delete('some path')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions