Type definition files, questions & feedback #683
-
Hi! I've got some questions and feedback regarding the typechecker and type definition files.
There are (at least) two ways to write the type definition for this function:
Let's use these to typecheck the following script:
So it seems the two type definitions are not really equivalent. Is this expected behavior? Does ordering in type unions matter, or this a bug in the typechecker?
For example, let's say I have a function which takes any number of strings: foo("a", "b", "c"...). In EmbeddedBuiltinDefinitions.cpp I can see "...number" used in the type definition of bit32.band, but
Well, actually I don't get an error message :) but LoadDefinitionFileResult.success is false after loadDefinitionFile call.
For example,
This causes loadDefinitionFile to fail without producing an error message.
Feedback: My number one wish would be simplified syntax for declaring function overloads. Something like this would be ideal:
This would be equal to but much more readable than:
(My wish number two would be documentation for the type definitions but I guess the syntax has not been finalized yet...) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
(I'll prefix this by saying these are just my own observations, and they might be wrong)
Its similar to how it works in general Luau syntax: https://luau-lang.org/typecheck#variadic-types
whilst in function type syntax, it'll be
Note that the error message is not stored directly in the LoadDefinitionResult.
AIUI, the type checker currently works greedily through function overloads, and goes with the first one which matches.
I've just been using
This syntax is valid for class method definitions, curiously it isn't for global functions 🤔. Would be great to see this be possible once definition syntax is stabilised declare class Foo
function overloaded(self, x: string): string
function overloaded(self, x: number): number
end |
Beta Was this translation helpful? Give feedback.
(I'll prefix this by saying these are just my own observations, and they might be wrong)
Its similar to how it works in general Luau syntax: https://luau-lang.org/typecheck#variadic-types
In function declaration syntax, it should be
whilst in function type syntax, it'll be
Note that the error message is not stored directly in the LoadDefinitionResult.
For parse errors, they will be in
result.parseResult.errors
For type er…