Skip to content

Mapped types: field access and 'Type T not found' errors #925

@mmpestorich

Description

@mmpestorich

Problem

Mapped types like Pick<T, K> show errors and don't resolve fields correctly for direct access.

Reproduction

---@alias Pick<T, K extends keyof T> { [P in K]: T[P]; }

---@param v {name: string, age: number}
local function use_person(v)
  print(v.name)  -- Field access works inside function
  print(v.age)
end

---@type Pick<{name: string, age: number, email: string}, "name" | "age">
local picked

use_person(picked)  -- No error here (type compatibility works)

print(picked.name)  -- ERROR: Undefined field `name`

Observed Behavior

  1. [type-not-found]Type 'T' not found error on the @alias Pick<T, K extends keyof T> line
  2. [undefined-field]Undefined field 'name' when accessing picked.name directly
  3. Type compatibility for function parameters appears to work (no error on use_person(picked))

Expected Behavior

  1. No "Type T not found" error on the alias definition
  2. Field access on mapped type variables should resolve correctly (e.g., picked.name should be string)

Environment

  • emmylua_ls version: 0.19.0
  • Editor: Neovim

Notes

The unit tests in generic_test.rs (test_type_mapped_pick, test_type_partial) only verify type compatibility via function parameters, not direct field access. This may explain why the feature appears to work in tests but not in practice.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions