Typed Luau Module Type Export Error

I am toying with typed luau, and I’ve run into an issue with the typechecker.

I am trying to create and export types in modulescripts, but when I try to access the type in the importing script, it gives me the error: “unknown type”.

Here is my code:

ModuleScript:

local module = {}

export type num = number

return module

ServerScript:

--!strict
local mod = require(script.ModuleScript)

local x: num = 5

Edit, Note: This error did not happen for one of my friends, even when using the same place file. Here is the place file: Type Error.rbxl (28.5 KB)

You need to require the module script first.

local mod = require(script.ModuleScript)

Do this:

export type(num) = number

Type is a function :grinning_face_with_smiling_eyes:

My bad, I forgot to include the require in the code snippet. The problem persists, though. Edited the place file and code.

No, that isn’t how type works in luau. I am using a variant of the official code snippet provided by the luau-lang.org documentation.

With luau you don’t have to make it a function. you will get syntax errors

Oh never knew that lol :grinning_face_with_smiling_eyes:

I checked it out and for some reason adding --!strict as the first line in the modulescript fixed it for me

image

image

Edit: And since this is from a modulescript, you need to get the type as if it’s a module variable

3 Likes