Skip to content
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

fix(component): do not exclude falsy types from LetDirective's input type #3460

Conversation

markostanimirovic
Copy link
Member

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[x] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

If we pass the property that contains falsy types to the LetDirective as follows:

@Component({
  selector: 'app-foo',
  template: `
    <div *ngrxLet="prop as alias">
      {{ prop }}
      {{ alias }}
    </div>
  `,
})
export class FooComponent {
  prop: Observable<string> | null | false = of('marko');
}

The type of prop within the embedded template will be Observable<string> (falsy types are excluded).
Fortunately, the type of the alias variable is correctly inferred (string | null | false).

What is the new behavior?

The type of both alias and prop is correctly inferred:

  • prop: Observable<string> | null | false
  • alias: string | null | false

Does this PR introduce a breaking change?

[ ] Yes
[x] No

@netlify
Copy link

netlify bot commented Jun 17, 2022

Deploy Preview for ngrx-io canceled.

Built without sensitive environment variables

Name Link
🔨 Latest commit 9835cb4
🔍 Latest deploy log https://app.netlify.com/sites/ngrx-io/deploys/62accdbf6564eb0008f45e24

@@ -105,8 +105,6 @@ export interface LetViewContext<PO> {
*/
@Directive({ selector: '[ngrxLet]' })
export class LetDirective<PO> implements OnInit, OnDestroy {
static ngTemplateGuard_ngrxLet: 'binding';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line was probably copied from NgIfDirective. It removes falsy types from the directive's input, which is not expected in the case of LetDirective.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could/want we a test for this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would require the "strictTemplates" setup for tests. AFAIK, that's not possible ("angularCompilerOptions" in tsconfig.spec.json doesn't affect tests).

@brandonroberts brandonroberts merged commit 7028adb into ngrx:master Jun 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants