From d3a92f29a882fee1fb22df3b99f0ed8d8f33b5c7 Mon Sep 17 00:00:00 2001 From: Jano Paetzold Date: Thu, 20 Apr 2023 21:24:34 +0200 Subject: [PATCH] Replace `@template T as X` with `@template T of X` in documentation According to https://github.com/vimeo/psalm/commit/1986c8b4a8018b1819bc4b83b0f7e69c2c936792#r108961921, `as` is an alias to `of`. However, only `of` is documented (in docs/annotating_code/templated_annotations.md). That caused me confusion reading this. I think as long as the alias is not documented, it's better to not use it in the docs. Even if it was documented, it would probably be better to not use aliases to avoid confusion. --- .../type_syntax/atomic_types.md | 2 +- .../type_syntax/utility_types.md | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/annotating_code/type_syntax/atomic_types.md b/docs/annotating_code/type_syntax/atomic_types.md index 7e3f0ea95..612cf9f7b 100644 --- a/docs/annotating_code/type_syntax/atomic_types.md +++ b/docs/annotating_code/type_syntax/atomic_types.md @@ -46,7 +46,7 @@ Atomic types are the basic building block of all type information used in Psalm. * [`key-of`](utility_types.md#key-oft) * [`value-of`](utility_types.md#value-oft) * [`properties-of`](utility_types.md#properties-oft) - * [`class-string-map`](utility_types.md#class-string-mapt-as-foo-t) + * [`class-string-map`](utility_types.md#class-string-mapt-as-foo-t) * [`T[K]`](utility_types.md#tk) * [Type aliases](utility_types.md#type-aliases) * [Variable templates](utility_types.md#variable-templates) diff --git a/docs/annotating_code/type_syntax/utility_types.md b/docs/annotating_code/type_syntax/utility_types.md index d2de471f4..4e690cbd4 100644 --- a/docs/annotating_code/type_syntax/utility_types.md +++ b/docs/annotating_code/type_syntax/utility_types.md @@ -148,7 +148,7 @@ $b = asArray(new B); /** @psalm-trace $b */; // array{foo: string, bar: int, baz: float} ``` -## class-string-map<T as Foo, T> +## class-string-map<T of Foo, T> Used to indicate an array where each value is equal an instance of the class string contained in the key: @@ -166,11 +166,11 @@ class Foo {} class Bar extends Foo {} class A { - /** @var class-string-map */ + /** @var class-string-map */ private static array $map = []; /** - * @template U as Foo + * @template U of Foo * @param class-string $class * @return U */ @@ -191,7 +191,7 @@ $bar = A::get(Bar::class); /** @psalm-trace $bar */; // Bar ``` -If we had used an `array, Foo>` instead of a `class-string-map` in the above example, we would've gotten some false positive `InvalidReturnStatement` issues, caused by the lack of a type assertion inside the `isset`. +If we had used an `array, Foo>` instead of a `class-string-map` in the above example, we would've gotten some false positive `InvalidReturnStatement` issues, caused by the lack of a type assertion inside the `isset`. On the other hand, when using `class-string-map`, Psalm assumes that the value obtained by using a key `class-string` is always equal to `T`. Unbounded templates can also be used for unrelated classes: @@ -250,8 +250,8 @@ Used to get the value corresponding to the specified key: