The OutputType
attribute is supposed to give type information through intellisense. However it does not work as expected.
I have tested this in both PSReadline and PowerShell ISE and they work the same.
The following is a sample function I am using:
Function Get-FirstChar
{
[OutputType([String])]
[CmdletBinding()]
param(
[Parameter(Mandatory=$true, ValueFromPipeline=$true)][string[]]$Strings
)
process {
foreach ($str in $Strings) {
$str.SubString(0, 1);
}
}
}
When I do:
"John","Simon" | Get-FirstChar | % { $_.<TAB> }
I get the suggestions (regardless of platform):
Equals GetHashCode GetType ToString
However when I do:
("John","Simon" | Get-FirstChar).<TAB>
Then I get all the string methods like SubString
etc.
I have also tried a string array String[]
as the output type and it still don't work :(
Can someone shed like on how to use OutputType
attribute to say that one or more strings will be returned from a powershell function?
Thank you