Comments (3)
Just make the class fields optional
---@class TestClass
---@field TestField number? A test field in test class
TestClass = {}
from lua-language-server.
Just make the class fields optional
Thanks for the suggestion! That was the first workaround I tried, but it gives off the wrong impression as real instances of the class always have the fields. It also makes it possible to pass a generic table to a function that only accepts the class.
So for a workaround for now I did this:
---Define a custom class for generic tables (workaround for LLS bug https://github.com/LuaLS/lua-language-server/issues/2606)
---@class any_table
any_table = {}
---@class TestClass
---@field TestField number A test field in test class
TestClass = {}
-- TestFunction1
---@param generic_table_or_testclass_instance any_table|TestClass
function TestFunction1(generic_table_or_testclass_instance) end
With this LLS is smart enough to allow both while keeping the strictness on functions that only accept a class. For functions that only accept a table I keep using the regular table
, I only use any_table
for overloaded function.
But I still think LLS should be fixed to make it work without the fake table class :-)
from lua-language-server.
Yes, it is a shame that there are too many specific use cases, I have also come across some things that I would like to do and it is not possible, I just accept it and hope that in the future,
After the famous Rework that they will do to LLS we should be able to cover all the problems and even be able to create solutions in itself with dynamic annotations or that execute lua code
from lua-language-server.
Related Issues (20)
- VSCode pop-up error `Request textDocument/documentSymbol failed.` when typing
- When using alias values as its keys, Dictionary types don't give completion when defining an instance of that dictionary
- Error returning derived classes
- Optional not removed in if/elseif block for field in filter
- 目录重命名, 移动目录, 在自动修改req路径时, 新路径会出现多余字符, 或者不修改
- [Future Ruquest] Add tracking for `rawset()` in function runtime and etc
- [Feature Request] Support custom file extension
- Command line doc_out_path arg doesn't work HOT 1
- Missing fields on inherited class not resulting in diagnostics warnings
- Function with generic variable return type loses typing after first return
- ---@class with function return question
- Update EmmyLuaCodeStyle HOT 1
- Is there a plan to implement Pylance using the Lua language? HOT 4
- injection into the standard library
- inherited injected field unknown
- Needs a "don't use truthy types in a conditional/boolean context" diagnostic HOT 1
- The type of keys used to index [] tables is not checked HOT 1
- BUG: 当_ENV作为多重赋值的第一个变量时, 后续变量会错误的识别成局部变量. HOT 1
- [Feature Request] @mixin - @class specific syntax to define applied mixins HOT 1
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 lua-language-server.