ngx-mask icon indicating copy to clipboard operation
ngx-mask copied to clipboard

directive patterns input should be optional

Open hv-pul opened this issue 3 years ago • 0 comments

🐞 bug report

Is this a regression?

No.

Description

patterns is defined as @Input() public patterns: IConfig['patterns'] = {}; However, it is only applied when an actual custom pattern is set:

    if (patterns && patterns.currentValue) {
      this._maskService.maskAvailablePatterns = patterns.currentValue;
    }

So the input should be defined as @Input() public patterns?: IConfig['patterns']; This would make it possible to allow for dynamic pattern values while keeping type safety.

🔬 Minimal Reproduction

https://stackblitz.com/edit/angular-ivy-mask-k4esrx?file=src%2Fapp%2Fdemo.component.ts

🔥 Exception or Error


 Type '{ [character: string]: { pattern: RegExp; optional?: boolean | undefined; symbol?: string | undefined; }; } | undefined' is not assignable to type '{ [character: string]: { pattern: RegExp; optional?: boolean | undefined; symbol?: string | undefined; }; }'.

  Type 'undefined' is not assignable to type '{ [character: string]: { pattern: RegExp; optional?: boolean | undefined; symbol?: string | undefined; }; }'.

🌍 Your Environment

Angular Version:


Angular CLI: 11.2.14
Node: 14.17.0
OS: darwin arm64

@angular-devkit/architect       0.1102.12
@angular-devkit/build-angular   0.1102.14
@angular-devkit/core            11.2.12
@angular-devkit/schematics      11.2.14
@schematics/angular             11.2.14
@schematics/update              0.1102.14
ng-packagr                      11.2.4
rxjs                            6.6.7
typescript                      4.1.5

hv-pul avatar Oct 05 '21 15:10 hv-pul