Comments (1)
This is intended since your implementation of button
is not a covariant of widget
, the error reported is accurate. However, you can achieve what you're after with types like:
---@class widget
---@field common string
---@class button : widget
---@field text string
---@field callback fun(btn: button, x: number, y: number)
---@class static__widget
local widget = {}
function widget.create()
return --[[---@type widget]] {
common = "some common field"
}
end
---@class static__button
---@field create fun(text: string, ): button
local button = {}
---@param text string
---@param callback (fun(btn: button, x: number, y: number))
function button.create(text, callback)
local button = --[[---@type button]] widget.create()
setmetatable(button, { __index = button })
button.text = text
button.callback = callback
return button
end
Basically your static class can be given its own type, that does not incorrectly indicate it inherits from the static widget type. Your button
however does still correctly inherit from widget
.
This is not just "correct", it's beneficial, you won't even see the create
function on instances of button
/widget
, which is important, because they're not compatible.
from intellij-luanalysis.
Related Issues (20)
- nil checks are not context-aware
- Hello, Is it possible to type a global value with Luanalysis ?
- Top and Bottom Types Distinct from "any" HOT 5
- Unnecessary '0 results are excess arguments' warning HOT 1
- Invalid type mismatch error is given when passing along optional `shape` from one function to another HOT 3
- Type mismatch error when assigning subclasses to an array of superclass HOT 2
- java.lang.NullPointerException HOT 2
- `table<>` definitions with incorrect Type Mismatch errors HOT 1
- Add std defs for LuaJIT
- Allow custom function definitions in table
- Support multi-line text in @field and @param comments
- There seems to be no way to define a non-nil generic return value for a function
- Wrong return type for os.execute
- error HOT 1
- Returned anonymous function is not type-checked HOT 1
- Luanalysis doesn't seem to understand manual nil check
- Executing the Rename action on some files causes severe freeze
- Lua code formatting moves some end-of-line comments to a new line
- Upgrade EmmyLua version. HOT 1
- Add support for multiline alias
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from intellij-luanalysis.