Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using es-6 symbols in typescript

Tags:

typescript

I'm trying to use symbols in my typescript code (using es-5 as target). However, the following code gives an error TS2304: Cannot find name 'Symbol'

var sym = Symbol();

According to the roadmap, symbols are supported since version 1.5. But I guess one thing is supporting symbols and a different one is transpiling symbols to es-5.

What is the best way to get symbols working in my es-5 transpiled code?

like image 753
Marco Avatar asked Jan 24 '16 13:01

Marco


1 Answers

By default TypeScript does not offer poly-fills for future changes to the standard library when compiling to older versions, it only offers syntactic changes.

That means Symbol is not available when compiling to ES5 but is available when compiling to ES6.

If you want to use ES6 standard library changes when compiling to older ES versions you can use core.js to get the poly-fills.

like image 77
toskv Avatar answered Sep 28 '22 17:09

toskv