While browsing through http://www.typescriptlang.org/docs/handbook/decorators.html#class-decorators, I encountered an issue where it could not find the Symbol
. I was unsure whether this is related to the usage of reflect-metadata
or if it was previously included in 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 am uncertain if I need to import something else related to Symbol. Has there been a change that I am unaware of? Any insights on what I might be doing wrong are appreciated.
Update:
After coming across a helpful comment by Amid at this link, it became clear that the issue might be related to ES6 and my TSconfig settings. Making some adjustments seemed to resolve the problem, but with a slight caveat.
- For instance, when switching to using es6 compiler option, an error message ->
Cannot find name 'Symbol'
appeared. - If the compile error disappears after making changes, adding variables etc., or even just a newline, the editor may indicate the same error again. However, recompiling seems to resolve the issue temporarily, although it does seem to recur periodically.