ty icon indicating copy to clipboard operation
ty copied to clipboard

support generic TypedDict

Open RyanSaxe opened this issue 1 day ago • 3 comments

Summary

TypeVars do not seem to be properly handled inside TypedDicts

from typing import TypedDict, reveal_type


class TestDictExample[T](TypedDict):
    id: int
    name: str
    active: bool
    bug: T


class Example[T]:
    def __init__(self, data: TestDictExample[T]) -> None:
        self.attr: TestDictExample[T] = data

    def do_something(self) -> T:
        value = self.attr["bug"] # ty thinks this is Unknown instead of T
        name = self.attr["name"] # ty correctly gets this as str
        return value

https://play.ty.dev/fa58789a-4d72-4f76-802d-7dafe74e52b8

Version

ty 0.0.5

RyanSaxe avatar Dec 23 '25 18:12 RyanSaxe