question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I need a way to shorten some type define.

For example, I have two variables defined like this:

---@type fun(result_count:number, result_map:Map<number,Map<number,table>>) | nil
local entity_search_result_callback1
---@type fun(result_count:number, result_map:Map<number,Map<number,table>>) | nil
local entity_search_result_callback2

Hard to write and understand! 😭

I want to do this:

---@typedef entity_id_t number
---@typedef component_id_t number
---@typedef entity_data_t Map<component_id_t,table>
---@typedef entity_data_map_t Map<entity_id_t,entity_data_t>
---@typedef success_callback_t  fun(result_count:number, result_map:entity_data_map_t) | nil

---@type success_callback_t
local entity_search_result_callback1
---@type success_callback_t
local entity_search_result_callback2

😎

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
tangzxcommented, Dec 3, 2018

new annotation: @alias usage: ---@alias NAME type

---@alias EventListener fun(type: string):void

---@param listener  EventListener
function m:addEventListener(listener)
end
1reaction
ice1000commented, Nov 28, 2018
---@class entity_id_t : number
---@class component_id_t : number
---@class entity_data_t : Map<component_id_t,table>
---@class entity_data_map_t : Map<entity_id_t,entity_data_t>
---@class success_callback_t : fun(result_count:number, result_map:entity_data_map_t) | nil

---@type success_callback_t
local entity_search_result_callback1
---@type success_callback_t
local entity_search_result_callback2
Read more comments on GitHub >

github_iconTop Results From Across the Web

C - typedef - Tutorialspoint
The C programming language provides a keyword called typedef, which you can use to give a type a new name. Following is an...
Read more >
typedef specifier - cppreference.com
The typedef specifier, when used in a declaration, specifies that the declaration is a typedef declaration rather than a variable or function declaration....
Read more >
typedef - Wikipedia
typedef is a reserved keyword in the programming languages C, C++, and Objective-C. It is used to create an additional name (alias) for...
Read more >
typedef definitions - IBM
When any extended language level is in effect, typedef redeclaration supports all types, including a variably modified type. End IBM extension. For more ......
Read more >
Typedef - MATLAB & Simulink - MathWorks
C Construct. typedef float float_32;. Procedure. To create a data type alias in Simulink®, use a Simulink.AliasType . The code generator creates a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found