Closed lorenzholzbauer closed 1 week ago
Add a typeof operator that returns the runtime object instead of a string like in JS.
typeof
For example:
Null:
var x: null = null; var y: type = typeof x; // -> null
Primitives:
var x: str = "x"; var y: type = typeof x; // -> str
Objects:
interface X { prop: num } var x: X = { prop: 1 }; var y: type = typeof x; // -> obj
Arrays:
var x: Array<num> = [1, 2, 3] var y: type = typeof x; // -> Array
Functions:
var x: Func<num> = (): num -> { return 1; }; var y: type = typeof x; // -> Func<num>
Class:
class Duck { ... } var x = new Duck(); var y: type = typeof x; // -> Duck
Implemented by #688
Is there an existing proposal for this?
This feature does not exist in the latest version
Proposal
Add a
typeof
operator that returns the runtime object instead of a string like in JS.For example:
Null:
Primitives:
Objects:
Arrays:
Functions:
Class:
Exact behaviour / changes you want
typeof
operator which is a built-in keyword that is separate from any references and such.typeof
.typeof
implementing the functionality for typeof.