Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript reflect-metadata Cannot find name 'Symbol'

I was reading this http://www.typescriptlang.org/docs/handbook/decorators.html#class-decorators

but, Error can not find Symbol, I do not know what it is Symbol if this is part of reflect-metadata or it was part of reflect-metadata

import "reflect-metadata"; //change for my path

const formatMetadataKey = Symbol("format");   <-- Cannot find name 'Symbol'.

function format(formatString: string) {
    return Reflect.metadata(formatMetadataKey, formatString);  <-- Work
}

function getFormat(target: any, propertyKey: string) {
    return Reflect.getMetadata(formatMetadataKey, target, propertyKey); <-- Work
}

I have to import something else to Symbol?, or this has changed, someone knows I'm doing wrong.


Update:

I think the solution is that Amid comment on ES6, for some circumstance, my TSconfig, was not working all that well, but after some changes worked, but as a note saying.

  • for example change or used es6 compiler option, it shows -> Cannot find name 'Symbol'
  • if you compile error disappears, but if you make changes to the file, adds something more variable ect or a simple newline, the editor indicates the error mentioned earlier, but if you recompile the error disappears and so all the time but seems to work.
like image 407
Angel Angel Avatar asked Mar 01 '26 21:03

Angel Angel


1 Answers

To get more info about Symbol read this document: link

To get rid of the error: target ES6 instead of ES5.

like image 167
Amid Avatar answered Mar 04 '26 11:03

Amid



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!