New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using namespace doesn't work for OutputType in Modules #13768
Comments
If anything, you might want a |
@vexx32, thanks for the comment. |
I've always understood it would work this way. If you import the the psm1 file, and then try |
@jhoneill, thank you for the explanation. |
@iRon7 :-) Things don't work the way most people would expect them to. The question, really, is how practical it is to change it to be logical. The |
Yeah, it's a scoped action; it only applies to the scope it's used for. You can scope it to a file, which might be a function, or a module, or a script. But unless you dot source that file (which merges the scope into your current scope) it doesn't apply outside that file. That said, I would tend to agree it should probably work for modules more consistently. I've seen a few less consistent issues with it in modules in the past... but I've also seen plenty of cases where this does work just fine (I use it in PSKoans in at least one or two functions). I wonder if the difference is that |
@vexx32 yeah, it's whatever scope the attribute happens to be compiled in. Very unlikely to be the scope where the type is resolvable. Part of the problem is that If |
I'm not sure I completely understand the reply. But the way I understood it was when (for example) you type |
Yeah pretty much. That information is queried from the current interactive scope.
It's less about whether
Without the ability to declare a namespace that would end with a lot of conflicts. For example it'd be interesting to see how many modules have a class named
I'm not sure the solution is to change the state of global, I'd rather see tab completion become aware of the callee's state. |
I guess we already have such issue. |
The still exists:
|
After creating a module out of a cmdlet, it appeared that I had to add theAdd-Type -AssemblyName
to resolve long .Net types.All shorthand types are now resolved as expected, except for the
OutputType
attribute in the[CmdletBinding()]
:When dot-source the file below as a PowerShell script (
. .\OutputType.ps1
file without theExport-ModuleMember
) it works fine, but when converted into a module, the shorten type (RuntimeDefinedParameterDictionary
) doesn't work for theOutputType
:Steps to reproduce
Module (
OutputType.psm1
) file:Import-Module .\OutputType.psm1 test
Expected behavior
Actual behavior
Workaround
Add full qualified type name to the
OutputType
attribute:Environment data
The text was updated successfully, but these errors were encountered: