Comments (3)
Rather than doing this auto-magically, I'd prefer a more explicit approach e.g.
---@class ServiceDefinition
---@overload ServiceDefinition:new
That way the one project can mix and match instantiation schemes, and if you're publishing a library, people can just use your library as is without needing to change Luanalysis preferences.
This actually touches a little bit on #5... Will comment more there.
from intellij-luanalysis.
from intellij-luanalysis.
(sorry for the double comment, I cleaned that up, the first one got posted too early...)
Any news ? :)
I'm asking because I'm still facing difficulties getting everything to work correctly for some more "complex" annotations:
(ignore that dummy Class
function, that's just for the sake of this screenshot)
As you can see here, for some reason the tmp
variable isn't typed as a MyClass
, even though everything else seems OK:
- the private fields are correctly typed if I ctrl-hover them in any class method. (thanks to the first part of the MyClass
@type
annotation) - the constructor is correctly recognized (thanks to the second part of the MyClass
@type
annotation)
BTW, I did try the following, but that didn't solve it completely (to be clear: it made the return value typed correctly, but the constructor parameters became unknown because MyClass
doesn't have the alternate function type that provided the info anymore)
---@class MyClass
---@overload fun(id:number, name:string, options:table<string,any>|nil):MyClass
Is this a bug somehow, or am I missing something? Or is it something that's known to be non-working right now and that would be handled later (with something like what you mentioned in the earlier comments)
Thanks!
Edit :
I found a way to make it work, but unfortunately the actual Lua code changes, and that's a no-no:
I guess the following is the only way to "dual-type" a class correctly.
---@class MyClass
---@overload fun(id:number, name:string, options:table<string,any>|nil):MyClass
---@field private id number
---@field private name string
---@field private options table<string,any>
local MyClass
---@type MyClass | fun(id:number, name:string, options:table<string,any>|nil):MyClass
local MyClass = Class()
[...]
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.