Type Annotations! A guide to writing Luau code that is actually good

I had only scratched the surface of type checking prior to reading this, but after reading it I feel a lot more confident using type checking while programming. Very well explained and structured!

1 Like

Is there a way to automatically put values into a type table? For example,

type t = {
  Name: “T”,
  
  Points: number
}

local specificT: t = {
  Points = 4
}

print(specificT.Name) -- this prints nil. How do we change it to automatically be T?

Is there a way to switch make it to modify the a part of b?
Like this

type a = {
	epic: string?,
	amazing: number?
}

type b = a & {
        epic: “This is b”,
	super: string?
}
type a = {
	epic: string?,
	amazing: number?
}

type b = {
	epic: "This is b",
	super: string?
} & a

local bb: b = {epic = "This is b" :: "This is b", super = ""}

I think this is the only way you can do it. The string type is not equal to the "This is b" type, so you must typecast it.

1 Like