Feature Request: Strict import scope and function signature semantics
See original GitHub issueSummary of the new feature/enhancement
The current version of PowerShell is actually a very runtime driven framework. Function calls are only checked runtime whether the function is present and the parameters are met. Import-Module instructions only execute runtime and there is no guidance design time which functions will be pulled into the current scope.
What we like to see is a more design time driven experience such as frameworks as TypeScript Nodejs. The benefit of the EcmaScript module system is that you know design time which functions you are pulling into scope. Additionally, the import process of Nodejs is much faster than PowerShell. The benefit of TypeScript is that function calls are validated design time. When a parameter or return type is not met, the file simply does not get compiled. PowerShell should block any function use that is not coming from an import statement. TypeScript nodejs files simply don’t compile when unknown functions are being called.
E.g.
# Import specific functions / cmdlets
Import Get-AzResourceGroup, Get-AzKeyVault from Az
Get-AzResourceGroup -Name xyz
# Import the whole set of exported functions / cmdlets to a variable
Import * as $Az from Az
$Az.Get-AzResourceGroup -Name xyz
# This should not compile / execute and should throw a parameter mismatch error
Get-AzResourceGroup -RandomParameter
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:18 (2 by maintainers)

Top Related StackOverflow Question
@rjmholt Has there been any recent development? Many of our bugs are caused by insufficient static analysis. Would it be easy to start with some manual decoration language so that you can help the language service? If we were able to adopt something like the TypeScript module import semantics, then the language service can limit its analysis to the particular file.
I’ve done some work toward this. Requires investment in a static parameter binding approximation algorithm. Which PSScriptAnalyzer has general need of. But this plus more performant profiles would be the silver bullet for static analysis.