I am working through an example in an ASP.Net Core 6 and Angular 13 book on Material Tables, paging, sorting and filtering.
The material table in my angular component html looks like this:
<table mat-table [dataSource]="cities"
class="mat-elevation-z8"
[hidden]="!cities"
matSort (matSortChange)="loadData()"
[matSortActive]="defaultSortColumn"
[matSortDirection]="defaultSortOrder">
And in the component ts file or the controller, it has defaultSortOrder initialized like this:
public defaultSortOrder: "asc" | "desc" = "asc";
I don't understand this syntax. I read it as: "asc" OR "desc" is assigned "asc".
It seems to work but I don't understand what is going on here. If I try to initialize it to just "asc",
public defaultSortOrder = "asc";
it says: "Type 'string' is not assignable to type 'SortDirection'."
I tried to read the documentation but I still don't get it.
What does this syntax mean?
public defaultSortOrder: "asc" | "desc" = "asc";