Make methods in custom classes support optional parameters · Issue #9701 · PowerShell/PowerShell · GitHub
Skip to content

Make methods in custom classes support optional parameters #9701

@mklement0

Description

@mklement0

Summary of the new feature/enhancement

#9684 shows that while you can declare optional parameters, they are in effect mandatory, and the default value is ignored.

Reporting an error when an attempt is made to declare an optional parameter is one solution, but a better option is to enable proper support for optional method parameters, so that the following would work:

# Wishful thinking
PS> class Foo { [string] Bar($Baz = 'Bam') { return $Baz } }; [Foo]::new().Bar()
Bam

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Enhancementthe issue is more of a feature request than a bugResolution-No ActivityIssue has had no activity for 6 months or moreWG-Languageparser, language semantics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions