, ExampleState.Unsaved
- , (let x: ExampleState.Unsaved
). Typescript ,
if (this.state === ExampleState.Unsaved)
- - Typescript this.state
ExampleState.Unsaved
.
, , ( ):
type ExampleState = -1 | 0 | 1 | 2;
class Example {
private state : ExampleState = -1;
public Save() {
if (this.state === 0) {
this.BeginSaving();
while (this.state === 1) {
this.CommitSave();
}
}
}
private BeginSaving() {
this.state = 1;
}
private CommitSave() {
this.state = 2;
}
}
, @Paleo, , Typescript ( - ). casting while
. , while
, JavaScript, .
while (this.state as ExampleState === ExampleState.Saving) { // no error
this.CommitSave();
}