Please add support for 'const' (immutable) variables and objects.

Topics: Language Specification
Oct 3, 2012 at 6:07 PM

See http://en.wikipedia.org/wiki/Immutable_object :

"In object-oriented and functional programming, an immutable object is an object whose state cannot be modified after it is created."

For example for variable and member declarations:

const MAX = 43;

But also for function parameters:

function foo( const bar : Bar ) { ... }

Thanks!

Coordinator
Oct 3, 2012 at 8:41 PM

The type system in TypeScript focuses on ECMAScript interfaces and features, so we likely won't support creating constants if ECMAScript doesn't support it.

That said, ES5 does allow you to create readonly fields (eg, using the Object.defineProperty), which we could look into supporting.