this happened to me now multiple times, so I want to ask if I´m doing something wrong or Typescript / Angular really dont do it. From my understanding one of the biggest strengths is the type declaration (interface) for variables, parameters and so on.
Today I had this problem:
A simple switch button:
<p-selectButton [options]="posLayouts" (onChange)="handle($event)" [(ngModel)]="pageSize"></p-selectButton>
The variables:
pageSize: number;
posLayouts: SelectItem[];
//On mistake I setted the value here as a string
this.posLayouts.push({label:'1 Woche', value: '1'});
this.posLayouts.push({label:'3 Wochen', value: '3'});
In the change function I simply call another function with the value out of posLayouts.
handle(e){getPager(this.pageSize)}
getPager(pageSize: number = 3){
let totalPages: number;
totalPages = 23 + pageSize -1
console.log(totalPages)
}
console.log(), returns than eiter 230 or 232 instead of the wanted 23 or 25. It takes pageSize as string. This type errors are hard to find, this time I had luck cause it was easy to find... Neither Angular or tslint or my editor tells me anywhere that I cant store a string in a number variable.
For my understanding, typescript should check for the compatiblity or does Angular somehow disable the listening here ? Or I´m doing something wrong ?