-
-
Notifications
You must be signed in to change notification settings - Fork 369
Closed as not planned
Labels
duplicateThis issue or pull request already existsThis issue or pull request already existsenhancementNew feature or requestNew feature or requestfeat/genericRelated to generic emulation featureRelated to generic emulation featurefeat/type checkRelated to the type checking featureRelated to the type checking feature
Description
@generic
seems to be behaving weirdly when being used in a class.
---@class Array<T>: { [integer]: T }
---@type Array<string>
local arr = {}
-- correctly warns that I am assigning a boolean to a string
arr[1] = false
-- no warning despite indexing with a string instead of an integer
arr["foo"] = "bar"
-- correctly does not warn as I am following the type correctly
arr[3] = "Correct"
Behaves even weirder for a dictionary:
---@class Dictionary<T>: { [string]: T }
---@type Dictionary<boolean>
local dict = {}
-- no warning despite indexing with a number
dict[1] = "incorrect"
-- no warning despite assigning a string
dict["foo"] = "bar?"
-- correctly does not warn as I am following the type correctly
dict["correct"] = true
The same issues exist when indexing with .
like dict.foo = "bar?"
Originally posted by @carsakiller in #1362 (comment)
Metadata
Metadata
Assignees
Labels
duplicateThis issue or pull request already existsThis issue or pull request already existsenhancementNew feature or requestNew feature or requestfeat/genericRelated to generic emulation featureRelated to generic emulation featurefeat/type checkRelated to the type checking featureRelated to the type checking feature