Skip to content

How to create a fallback type for undefined string fields? #3221

Answered by tomlau10
sewbacca asked this question in Q&A
Discussion options

You must be logged in to vote

A fix for only adding fallback type when field type not found

I debugged quite a while, and finally found a fix for this 🤔

  • the reason of this behavior is that it always processes all @field types info, before looking into setfield/setmethod of the class variable
  • by delaying only the processing of @field [T1] T2, we can then first check if a field type is already found
  • and finally add the fallback type only if that field key type not found

However I am not sure if there are any side effects, at least it pasts all existing defined test in the project 😕

demo

---@class Vector
---@field x number
---@field y number
---@field z number
---@field [string] Vector
---@operator add(Vector): Vector
l…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@tomlau10
Comment options

@sewbacca
Comment options

@tomlau10
Comment options

Answer selected by sewbacca
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants