Tag Archives: typescript

[Solved] error ‘xxx‘ is never reassigned. Use ‘const‘ instead prefer-const

If let or var variables are used to declare in TS, an error will appear:

Slint: identifier ‘errmsg’ will never be reassigned; Use ‘const’ instead of ‘let’. (prefer const)

code snippet:

Solution:

1. Use const to declare
2. Open tslint.json file under the project, set prefer-const to false.

vue3 import Error: has no default export [How to Solve]

In the vue3 project, the TS write error component does not export by default because vetur-v0 35.0 does not support vue3. You need to download Vue language features (vol) – v0 twenty-nine point eight

<template>
     <MyHeader></MyHeader>
</template>
<script setup lang="ts">
import MyHeader from "../components/MyHeader.vue";
</script>

How to Solve Vscode terminal error (ts -v)

Solution: (test available)
run PowerShell as an administrator and execute the command set-ExecutionPolicy RemoteSigned to change the execution policy of PowerShell to RemoteSigned

1. Win + X: select windows PowerShell to open the shell
2. Run set-ExecutionPolicy RemoteSigned command and enter y
3. Run get-ExecutionPolicy command to see that the execution policy of the script has been changed to RemoteSigned
4. Return to the vscode terminal and enter the command TSC – V to stop reporting errors, TS files can also be compiled

[Solved] error: Unexpected console statement (no-console)

Solution:

Modify package Eslintconfig in JSON: “rules”: {} in {}, add a line of code: “no console”: “off”

NPM install after saving

module.exports = {
  root: true,
  env: {
    node: true
  },
  extends: [
    'plugin:vue/essential',
    '@vue/standard'
  ],
  parserOptions: {
    parser: 'babel-eslint'
  },
  rules: {
    'no-console': process.env.NODE_ENV === 'production' ?'warn' : 'off',
    'no-debugger': process.env.NODE_ENV === 'production' ?'warn' : 'off',
    "no-console":"off"
  }
}

Or directly use:

window.console.log(“…”) (I haven’t tried)

[Solved] Typescript installation TS node execution error

1.First time using ts Install ts-node compile error
1.1 Installing typescript
npm install typescript -g || yarn global add typescript
1.2 Install ts-node to execute code
npm install -g ts-node

2. Install it again at this point
npm install -D tslib @types/node
3. Then execute the ts-node file name and you’re done

Typescript generic source code error

1. The error information is as follows

2. Source code understanding

export declare type InputProps = Pick<React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, 'maxLength' | 'autoComplete' | 'enterKeyHint' | 'pattern' | 'type' | 'onFocus' | 'onBlur' | 'autoCapitalize' | 'autoCorrect'> & {
    value?: string;
    defaultValue?: string;
    onChange?: (val: string) => void;
    placeholder?: string;
    disabled?: boolean;
    readOnly?: boolean;
    clearable?: boolean;
    onClear?: () => void;
    id?: string;
} & NativeProps<'--font-size' | '--color' | '--placeholder-color' | '--disabled-color'>;

React.inputhtmlattributes have the following names in react

type DetailedHTMLProps<E extends HTMLAttributes<T>, T> = ClassAttributes<T> & E;

3. Solution

The version of react declaration file is too low. The following declaration is missing

Solution to errors reported by TES command in vscode – errors reported by typescript command

    start vscode as an administrator, open the terminal, enter the command get executionpolicy as follows
    , and then enter the command set executionpolicy remotesigned. If it is normal, there is no problem. If an error is reported as follows
    , then enter the command set executionpolicy – scope currentuser
    , and then enter remotesigned at the position shown in the figure

Ts-node Error: return new TSError(diagnosticText, diagnosticCodes);

TS node can help us run the TS code without manually converting it into a JS file

But we passed

npm install -g typescript
npm install -g ts-node

After installing the two packages, running the file with the TS node command may report an error and cannot be executed

At this time, we need to install one more dependency package

npm install -D tslib @types/node

Just run it with TS node

After node.js is installed, use the instruction node version in vscode to show that it is not an external or internal instruction. The solution is as follows:

**

After node.js is installed, use the instruction node version in vscode to show that it is not an external or internal instruction. The solution is as follows:

**

Method 1: restart vscode, and then re-enter node — version (1) find the code.exe file
(2) right click the properties
(3) after opening the compatibility, select to run the program as an administrator and click OK
(4) in the last step, restart vscode and re-enter node — version

The page console error [Vue warn]: Invalid prop: custom validator check failed for prop “status“

Invalid prop: custom validator check failed for prop “status” encountered during project debugging##

First of all, I was confused. I went to the prop and didn’t have status. I really couldn’t figure out what was going on. Through the global search of status, I realized that it was the problem of style components. Because of the company’s confidentiality, I really wanted to simulate the code

<el-progress  :percentage="stepPercentage(item.step)"  status="error"></el-progress>

The status in this code is the key to error reporting. The reason is that I added an unknown attribute error of status, which makes it unrecognizable

be careful

1. The value of status can only be one of “success/exception/warning”. Other values will give the above warning. If you have to judge according to the conditions and need to give the default color, you can assign null [null, no quotation marks] to the value

<el-progress  :percentage="stepPercentage(item.step)" :status="item.step == 4 ?'success' :null"></el-progress>

2. You can’t have spaces in the parameters following status. You need to correct the format