Azure / Azure/bicep

Narrowed Typing within Resource & Modules

Open
#16,564 2 comments 0 reactions 0 assignees View on GitHub
enhancement type system
Dominant language
Bicep
Stars
3.6k
Forks
830
Avg merge
1d 21m
Merged PRs (30d)
79

Description

**Introduction**
As a programmer, I’m used to relying on control flow analysis—specifically type narrowing—in my coding experience, and it’s always felt intuitive. However, I’ve run into an unexpected behavior with Bicep that deviates from this expectation.

In my example, I’ve defined a parameter stack with the type `param stack: 'dotnet' | 'java' | 'node' | 'php' | 'python' | 'ruby' | null,` meaning it can either be one of these specific string literals or null. The issue arises when I attempt to use this stack variable in the `CURRENT_STACK `field.

Bicep complains if `null `is provided, which is reasonable since the field likely requires a non-null value. To address this, I added a null check using `!empty(stack) ` within an if statement to ensure stack isn’t null before proceeding. Despite this check, Bicep still raises a warning and suggests using` !stack` to suppress it. This surprises me, I’d expect Bicep to recognize the `!empty(stack)` condition and narrow `stack`’s type to `'dotnet' | 'java' | 'node' | 'php' | 'python' | 'ruby'` within that scope, eliminating the need for further assertions.

![Image](https://github.com/user-attachments/assets/bbafc05e-7e77-422a-b3a7-4c0b414ee03e)

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the Bicep example described in the issue and inspect the diagnostic produced for !empty(stack) when assigning stack to CURRENT_STACK. No files or tests are named; done means confirming whether this condition can narrow the nullable string-literal union without requiring an additional assertion, with regression coverage for the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure
Domain
compilers, devtools
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.