TypeScript exports is not defined

后端 未结 6 1669
攒了一身酷
攒了一身酷 2020-12-13 08:45

I\'m trying to use export and import but it not working I get an error

Here is my code HTML :




    <         


        
6条回答
  •  醉话见心
    2020-12-13 09:16

    try the following changes

    HTML:

    
    
    
        
        
    
    
        @RenderBody()
    
         
        
    
    
    

    tsconfig.json

    {
      "compilerOptions": {
        "module": "commonjs",
        "target": "es5",
        "sourceMap": true,
        "outFile": "~/scripts/main.js",
        "lib": [
          "dom",
          "es2015",
          "es5",
          "es6"
        ]
      }
    }
    

    with this config your output is only one js file what can be uglified wunderfull, containing all referenced files in the main.ts. i just don't know if ~/ works or if you have to set the path relative to the config file, i'm not working with linux.

    User.ts

    class User {
        firstName: string;
        lastName: string;
    }
    

    Main.ts:

    /// 
    
    // import { User } from "./user"; // not needed if referenced
    console.log(new User());
    

    all reference declarations have to be written at the beginning of the file

提交回复
热议问题