Dependent return value types for declared functions #2014
|
I'm trying to implement support for Luau's Analyzer via Luau LSP for Visual Studio Code in my runtime. I've gotten most of the way there, and the main thing left is adding a function which returns a type dependent on it's input, similar to Essentially: local animal = Object.createWithComponent("Deer")
-- type of `animal` should be "Object & Deer", where `Object` and `Deer` are already defined external types
-- `animal` should have the combined members of `Object` and `Deer` |
Answered by
PhoenixWhitefire
Mar 13, 2026
Replies: 2 comments
|
I think I should ask this on the Luau LSP repository instead |
0 replies
|
Here's what I eventually ended up using: type Creatables = {
Deer: Deer,
Fox: Fox,
Rabbit: Rabbit
}
declare Object: {
createWithComponent: <T>(T & keyof<Creatables>) -> Object & index<Creatables, T>
} |
0 replies
Answer selected by
PhoenixWhitefire
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's what I eventually ended up using: