#TypeChecker or sum idk what that is called
1 messages · Page 1 of 1 (latest)
I wanted to declaire functions outside of the module so I have 1 nest less and this is the only possible way it seems to work
huh
why would u need strict or export type
if u just want to have function accessable outside module
im trying to learn strict and export type rn
wait what r u exacly trying to do
i am trying to understand how to use TypeChecker, I learnt that : any isnt that legitim to use cause it simply "destroys" the use of --!strict and I wanted to know if its legitim todo it like this that I can declaire functions after creating the table
--!strict
export type Core = {
DEBUG: boolean,
_VERSION: string,
func : (self: Core) -> ()
}
local core : Core = {
DEBUG = false,
_VERSION = "0.1",
func = function() -- I dont want this here
print("test")
end
}
return core
Maybe this explains it better
But if I give func the Type any I am able to make it nil and then "declaire" it outside of the table
--!strict
export type Core = {
DEBUG: boolean,
_VERSION: string,
func : (self : Core) -> ()
}
local core : Core = {
DEBUG = false,
_VERSION = "0.1",
func = function(self : Core) end
}
core.func = function(self : Core) -- This is fine
end
return core
like this it would also work and I wouldn't use any
if i may weigh in on this, given i've worked a good amount with metatables, oop and typechecking:
first - https://luau.org/typecheck is a gold mine of info. it will serve you very well if you read it in full.
for this situation, changing func to : any will not help as it will continue to remain any outside the module. what this would require is for the module table to be unsealed after declaration, which is not possible after you leave the scope.
but i have a bit of a pattern i found.
A fast, small, safe, gradually typed embeddable scripting language derived from Lua
what do we think of this Numeric
"would require is for the module table to be unsealed after declaration, which is not possible after you leave the scope"
I didn't understand this at all btw
i see
ill see if i understand the problem correctly first
you want to declare functions outside of the module
ok. basically this is not normally possible
because outside of the module, the table is "sealed"
meaning the type channot change.
i think i am
I dont want this
this is fine
export type Core = {
DEBUG: boolean,
_VERSION: string,
func : (self : Core) -> ()
}
local core : Core = {
DEBUG: boolean,
_VERSION: string,
-- I dont want the function to be declaired in here
}
-- But here
return core
Theres not really a problem here
yea that makes sense now
I just wanna know if it is legitim todo func : any and declaire it outside
or do it like this
got it.
in that case func : any is technically legitimate but will not allow further typechecking (it will always result in any)
the second method is better.
no problem, sorry for the flip-flopping back there
all good