These scenarios below are accepting and non-acceptable declarations.
export class MyComponent{
Why does TypeScript accept a value as a data type?
This is extension of string literal types, this PR explains it: literal types
How does JavaScript handle these at compile time?
Its pure typescript creation, that will not affect resulting javascript.
How does it differ from readonly and constant?
Well - it will not be readonly. It will just allow one value. Check this example:
export class MyComponent
{
readonly error = 1;
error1: 1 = 1;
public do()
{
this.error = 1; //Error. The field is readonly
this.error1 = 1; //No error - because the field is not readonly
this.error1 = 2; //Error. Type mismatch
}
}