Giter VIP home page Giter VIP logo

Comments (3)

MillhioreBT avatar MillhioreBT commented on September 26, 2024

Just make the class fields optional

---@class TestClass
---@field TestField number? A test field in test class
TestClass = {}

from lua-language-server.

b-stage avatar b-stage commented on September 26, 2024

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.

MillhioreBT avatar MillhioreBT commented on September 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.