I want to create a structure for my dictionary via type checking.
What is the issue?
The issue is that it does not not raise a type error, despite being strict when the value is not a number.
Types module:
export type _PlayerContainer = {
[{PlayerName: string}]: {
[{Coins: string}]: number
}
}
Main script:
local Players:Types._PlayerContainer = {
["ByGermanKnight"] = {
["Coins"] = "fadsad" <-- Does not raise a type error,
-- despite not being a number
},
}
Your type is fundamentally malformed. The correct way to annotate that dictionary is as follows:
-- Private values should not be exported. Declare "PlayerContainer" as a public type by removing the "_" prefix.
export type PlayerContainer = {
[string]: {
Coins: number,
}
}