Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use emoji in typescript variable naming

Tags:

typescript

When a variable name contains an emoji in my typescript file, I get error 1127 Invalid Character. I'd like to use emojis to provide some visual cues in my source code.

Is there a good reason not to use emojis in a .ts file?

Is there an option I can use to disable to this error my tsconfig.json file?

const 🎻myVar: string = "hello"

tsconfig.json

{
  "extends": "./tsconfig.path.json",
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "strict": false,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react",
    "downlevelIteration": true,
    "typeRoots": [
      "node_modules/@types",
      "custom_typings/"
    ]
  },
  "include": [
    "src",
    "custom_typings"
  ]
}

EDIT: See this article for a detailed explanation of why emojis are not allowed in js variable names (https://thekevinscott.com/emojis-in-javascript/)[https://thekevinscott.com/emojis-in-javascript/]

TSC version: 4.0.2

like image 445
ANimator120 Avatar asked Oct 21 '25 11:10

ANimator120


1 Answers

Javascript, and therefore typescript, do not support emoji identifiers.

You can use some unicode characters like var ಠ_ಠ = 42 but emoji are not supported. There is no setting to make this work because it does not work in javascript.

Some more technical detail on this here: https://mathiasbynens.be/notes/javascript-identifiers-es6

like image 184
Alex Wayne Avatar answered Oct 23 '25 02:10

Alex Wayne



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!