Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Support for optional template syntax #7105

Closed
Milestone
@VincentLanglet

Description

Feature request

When describing an array, you can write

array => Reported as an error level 6
array<string> => no errors
array<string, string> => no errors

If I wand to create a similar generic,

/**
 * @phpstan-template TKey of array-key
 * @phpstan-template TValue
 */
class MyArray {}

I didn't find a way to make a template param optionnal,
so MyArray<Foo> is giving an error because I does not specify all template types

A syntax like

/**
 * @phpstan-template ?TKey of array-key
 * @phpstan-template TValue
 */
class MyArray {}

could be useful.

In order to avoid issue with

/**
 * @phpstan-template ?T1
 * @phpstan-template T2
 * @phpstan-template ?T3
 */

we might decide that all the optional template should be last, and are filled in the order they are defined.

/**
 * @phpstan-template T1
 * @phpstan-template ?T2
 * @phpstan-template ?T3
 */
Foo<T1> => Valid
Foo<T1, T2> => Valid
Foo<T1, T2, T3> => Valid
Foo<T1, T3> => Invalid

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      AltStyle によって変換されたページ (->オリジナル) /