3 ms·
TypedDicts fall under structural typing, not nominal typing. So Mypy is cool with this: import typing class Foo(typing.TypedDict): a: int def
by goodoldneon 4y ago
TypedDicts fall under structural typing, not nominal typing. So Mypy is cool with this:
import typing
class Foo(typing.TypedDict):
a: int
def do_thing(value: Foo) -> None:
return
foo: Foo = {"a": 1}
do_thing(foo)
My complaint here is that Mypy doesn't go far enough with structural inference. I assume this is because it doesn't support anonymous TypedDicts, whereas TypeScript supports anonymous interfaces/types