React+TypeScript solves file error reporting

(The most important thing to use TypeScript is the definition of the data type. If there is no definition, the page property will have a downline error. Although it does not affect the operation of the page, it looks very ugly. I have summarized a few common problems encountered in my work. problem situation)

1. Import the less file

Copy the code snippet directly:

declare module '*.css';
declare module "*.png";
declare module '*.less' {
  const classes: { [key: string]: string };
  export default classes;
}

2. When importing umi internal method to report an error

Copy the code snippet directly:

    "paths": {
      "@/*": ["./src/*"],
      "@@/*": ["./src/.umi/*"]
    },

 3. When the component is introduced, the first attribute value of the incoming parameter always reports an error, and a red underline appears

The reason for this is that the type of the receiving parameter is not defined in the component, and it must be defined in the component before use

Problem reproduction:

(Introduced subcomponents, the first attribute always appears underlined and reports an error)

Solution: 

For example in the breadCrumb component. First define IProps so that the incoming firstMenu will not have a red underline warning

 If you use the component again, you will not report an error

Guess you like

Origin blog.csdn.net/qq_41916378/article/details/123626981