#Type checking a key in a module dictionary?

53 messages · Page 1 of 1 (latest)

finite geyser
#

The title says it all, I've exported a type from a module script and would like to use it in another module script like this:

  module.StringVar: string = "Hello"

The problem is that this doesn't work. Is there a way to assign a type to this or is it just not possible?

narrow pulsar
#

i dont really understand probally because im not very good at scripting but couldnt you do a table and store the type inside the table? in the module

wet latch
#

Not sure if you can use typechecking using them

#

I mean you should be able to technically speaking

finite geyser
wet latch
#

Then what’s the issue?

finite geyser
#

I can do this

local var: mytype = "hello
finite geyser
#

^ that doesn't work

#

This will just error

wet latch
#

Quite sure you’ll have to create them in that class

finite geyser
#

this won't work either

wet latch
finite geyser
wet latch
#

Hovering over red underlined parts should show the error

finite geyser
#

which means that it will error

wet latch
#

Oh right

#

It thinks you’re calling a function

#

How do you typecast a function again… fuck I forgot

finite geyser
wet latch
#

No the function call

finite geyser
#

what

#

you can just do

local randstring: string = myfunc()
wet latch
#

Wait that was the same? I must quickly say

#

I hate typechecking past just the params of functions

finite geyser
#

The issue is it's not a local variable but rather a key in a dictionary

#

Type checking a key in a module dictionary?

finite geyser
#

That does carry over the type into module.Standard but I have to create that as a local variable and then assign it as a key

wet latch
#

I taught it was a function returning a metatable

finite geyser
pine delta
#

why would you even need that

#

tbh

wet latch
#

That actually confuses me more

finite geyser
wet latch
pine delta
finite geyser
#

It's VERY useful

wet latch
pine delta
#

my code doesnt error

finite geyser
#

especially in cases like this where it would take me forever to find the error only to find I misspelled one of the keys

finite geyser
wet latch
pine delta
pine delta
finite geyser
#

it's just good practice

#

It also gives you autocomplete when creating new class instances which is useful