I literally just wrote this template a few hours ago & it was functioning perfectly, but now I’m receiving several type errors?
Error:
Code:
--!strict
-- Properties
type Properties = {
name: string,
balance: number
}
-- Methods
type Methods = {
__index: Methods,
new: (name: string, balance: number) -> Object,
deposit: (self: Object, credit: number) -> (),
withdraw: (self: Object, debit: number) -> (),
}
-- Type
export type Object = typeof(setmetatable({} :: Properties, {} :: Methods))
-- Module Table
local Object: Methods = {} :: Methods
Object.__index = Object
--[[ Constructor: Creates a new Object. ]]
function Object.new(name, balance): Object
local self = setmetatable({}, Object)::Object
-- Properties
self.name = name
self.balance = balance
-- Return Object
return self
end
--[[ Deposit: Adds the amount to total. ]]
function Object:deposit(credit)
self.balance += credit
end
--[[ Withdraw: Removes the amount from total. ]]
function Object:withdraw(debit)
self.balance -= debit
end
-- Return Module
return Object
I can no longer access the properties or methods of my class within itself, which I was able to do earlier today & the code has not been altered in any way since.
I have a decent internet connection, I’ve reloaded studio several times, & I also tried enabling/disabling the new type checker beta feature but this did not solve the issue.