Skip to content

Commit 62030b6

Browse files
committed
a note about type bounds
1 parent 516a4d5 commit 62030b6

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

pep.rst

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -543,8 +543,15 @@ and we want typechecking to match.
543543
Type operators
544544
--------------
545545

546-
Note that in some sections below we write things like ``Literal[int]`` to mean
547-
"a literal that is of type ``int``".
546+
Many of the operators specified have type bounds listed for some of
547+
their operands. These should be interpreted more as documentation than
548+
as exact type bounds. Trying to evaluate operators with invalid
549+
arguments will produce ``Never`` as the return. (There is some
550+
discussion of potential alternatives :ref:`below <strict-kinds>`.)
551+
552+
Note that in some of these bounds below we write things like
553+
``Literal[int]`` to mean "a literal that is of type ``int``".
554+
We don't propose to add that as actula syntax yet.
548555

549556
.. _boolean-ops:
550557

@@ -1644,16 +1651,20 @@ not yet integrated into the main proposal) would improve the syntactic
16441651
situation at lower cost.
16451652

16461653

1654+
.. _strict-kinds:
1655+
16471656
Make the type-level operations more "strictly-typed"
16481657
----------------------------------------------------
16491658

16501659
This proposal is less "strictly-typed" than TypeScript
16511660
(strictly-kinded, maybe?).
16521661

16531662
TypeScript has better typechecking at the alias definition site:
1654-
For ``P[K]``, ``K`` needs to have ``keyof P``...
1663+
For ``P[K]``, ``K`` needs to have ``keyof P``. The ``extends``
1664+
conditional type operator narrows the type to help spuport this.
16551665

1656-
We could do potentially better but it would require more machinery.
1666+
We could do potentially better but it would require quite a bit more
1667+
machinery.
16571668

16581669
* ``KeyOf[T]`` - literal keys of ``T``
16591670
* ``Member[T]``, when statically checking a type alias, could be

0 commit comments

Comments
 (0)