angular / angular/angular

Type checking for structural directive without parameter

Open
#46,749 5 comments 1 reaction 0 assignees View on GitHub
area: compiler bug compiler: template type-checking P3
Dominant language
TypeScript
Stars
101k
Forks
27.5k
Avg merge
1d 19h
Merged PRs (30d)
288

Description

### Which @angular/* package(s) are the source of the bug?

Don't known / other

### Is this a regression?

No

### Description

Hello,
not sure if this is an actual issue or just me misunderstanding behaviour of structural directives in Angular.

Let's say we have a simple structural directive (see [repro](https://stackblitz.com/edit/angular-ivy-vbzbnj?file=src%2Fapp%2Funless.directive.ts,src%2Fapp%2Fapp.component.html,tsconfig.json,src%2Fapp%2Fapp.module.ts,src%2Fapp%2Fapp.component.ts)). From my point of view, two declarations below should be equal, however, the first one throws type error, while the second one compiles without any errors. Why is that?

```ts

Test

Test

```

From my point of view, typechecker expects the structural directive without any parameters to be equal to following:

```ts

Test

````

when in reality, it is equal to code above (I tried to change the type of the directive parameter to `boolean | string`, and checked if the input setter will be called - it wasn't).

### Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/angular-ivy-vbzbnj?file=src%2Fapp%2Funless.directive.ts,src%2Fapp%2Fapp.component.html,tsconfig.json,src%2Fapp%2Fapp.module.ts,src%2Fapp%2Fapp.component.ts

### Please provide the exception or error you saw

_No response_

### Please provide the environment you discovered this bug in (run `ng version`)

_No response_

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with the StackBlitz reproduction, especially src/app/unless.directive.ts, src/app/app.component.html, tsconfig.json, src/app/app.module.ts, and src/app/app.component.ts. Reproduce the differing type-checking behavior for *appUnless and the equivalent ng-template form, then trace Angular's structural-directive template checking. Done means the behavior is explained and the two forms are handled consistently if the reported behavior is confirmed.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.