Autofill for framework using type checking

So after learning about type checking I had come to a realization that I can use it for auto filling when using framework/metatables. But there is currently a situation where I am getting stuck and not able to solve. I want to be able to autofill my scripts which are module scripts that are required and loaded and setmetatable with index so that it can have framework functions. The framework functions are not able to autocomplete when using self. in the script so I tried to type checking my script by adding a type check on top of each script.

local Script: framework= {}

function Script:Setup()
     self. -- autocomplete then should do it
end

return Script

Well about that I cannot set type in the script loader which is usually a server/local script. When ever I type check it in the loader it won’t replicate to the module and I can’t export type from the loader to the script and because of that I must do this

local types = require(path.to.types)

local Script: types.framework = {}

function Script:Setup()
     self. -- autocomplete then should do it
end

return Script

Now because of that it looks messy and I would have to do require for every script .So instead of type checking the table I will type check the arguments.

local Script= {}

function Script:Setup(self : type)
     self. -- autocomplete then should do it
end

return Script

Still it is a problem because I cannot or get the type from the loader to import it in the module. That the situation I cannot or neither get the type from loader unless I require the module to export the types.

1 Like

#help-and-feedback:scripting-support please.

Also, did you try this?

function Script.Setup(self:Script)
1 Like

Well… that should work but it doesn’t because of how my framework works. Well when the game start the loader require the compiler then it took the framework functions in the compiler and setmetatable or __index it to the script. Which usually don’t autofill.
image

Is the framework using the compiler or script stored in a table of modules?

1 Like

The compiler is where it stored all the framework functions which are use to setmetatable to the script and modified when being required by the loader. The scripts are stored in a folder and are required by the loader using loop. Kinda like yucon framework, I accidently connect the framework to the script so there are confusion

I don’t think it gonna be possible unless I require the types module it the script itself then it will be able to recognize the types and start autocomplete

I found a solution to solve this ridiculous situation by changing my Scripts folder into an actual module script and when I create a new script I require the script parent and create a new table. Combining these 2 posts I was kinda able to solve my problem.

Can we see more about the code and structure behind the scenes you used to solve this?

1 Like

Well… in my framework I would do it like this:
A Core to store all the important stuff such as:

Compiler where all the framework functions are stored ( Doesn’t matter with autofill )
Config store all the Settings ( Doesn’t matter with autofill )
Types where all the types get stored and exported ( Required )
image

In my Client I would have:

A Loader which loads all the Scripts Children ( Doesn’t matter with autofill but needed to load the Scripts Children)
A Scripts Folder ( Currently a Module Script for autofill. Required ) which stored all the Scripts
image

Here how the process work:
The Scripts Folder ( Module Script ) require the Compiler to get the framework functions or no and require the Types module

Then the Script Children will require it parent which will direct to the Scripts Folder where it return a table to autofill.

The code for the Scripts Folder

--Types
local Types = require(game:GetService("ReplicatedStorage").Shared.Core.Types)

--Game's Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--Shared
local Shared = ReplicatedStorage:WaitForChild("Shared")

local Core = Shared:WaitForChild("Core")

--Compiler
local Compiler = require(Core["Compiler"])
local SharedFunctions = Compiler["Shared"]

local function New()
	return setmetatable({}, {
		__index = SharedFunctions -- You can either set __index or don't but must return a table with assigned type
	}) :: Types.Client --Require for the Script to autofill framework functions
end

return New()

The code for the Types module

type Dictionary = { [string]: any }
type DefineDictionary<Type> = { [string]: Type }

export type Table = { [any]: any }
export type DefineTable<Value> = { [string]: Value }

export type Array = { [number]: any }
export type DefineArray<Type> = { [number]: Type }

export type Function = (...any) -> ...any
export type DefineFunction<Return> = (...any) -> Return

export type Shared = {
	NewSharedClass: (self: any, ClassName: string, Recursive: boolean | any, ...any) -> Table,
	GetSharedClass: (self: any, Name: string, Recursive: boolean) -> Table,

	GetSharedModule: (self: any, Name: string, Recursive: boolean) -> Table,

	GetEngine: (self: any, Name: string, Recursive: boolean) -> Table,
	GetLibrary: (self: any, Name: string, Recursive: boolean) -> Table,

	GetService: (self: any, Name: string, Recursive: boolean) -> Table,

	GetPackage: (self: any, Name: string, Recursive: boolean) -> Instance | Table,

	GetSharedAsset: (self: any, Name: string, Recursive: boolean) -> Instance | Table,
	GetAllSharedAssets: (self: any) -> DefineArray<Instance>,
} & ExternalShared

export type Client = {
	Setup: (self: any) -> never,

	Heartbeat: (self: any, Time: number) -> never,
	Stepped: (self: any, Time: number) -> never,
	RenderStepped: (self: any, Time: number) -> never,

	Start: (self: any) -> never,

	NewClass: (self: any, ClassName: string, Recursive: boolean | any, ...any) -> Table,
	GetClass: (self: any, Name: string, Recursive: boolean) -> Table,

	GetModule: (self: any, Name: string, Recursive: boolean) -> Table,

	GetGui: (self: any, Name: string, Recursive: boolean) -> GuiBase2d,
	GetBackpack: (self: any, Name: string, Recursive: boolean) -> BackpackItem,

	Warn: (self: any, any) -> never,

	Classes: Folder,
	Modules: Folder,
	Scripts: Folder,

	Player: Player,
	Gui: PlayerGui,
	Backpack: Backpack,
	Character: Model,
	Assets: Folder,
} & Shared & ExternalClient

type ExternalShared = {}
type ExternalClient = {}

return nil

Oh also I just know you can do this

export type Client = {
	Scripts: typeof(Scripts Folder)
} & Shared & ExternalClient

You get every scripts children in the scripts folder

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.