Module vs Namespace - Import vs Require Typescript

后端 未结 5 1262
攒了一身酷
攒了一身酷 2020-12-04 05:14

I am getting lot of confusion with module/namespace/export and import, require, reference usage. Being from Java background, Can someone explain me

5条回答
  •  广开言路
    2020-12-04 06:00

    "require" and "import" are equivalent in functionality. we can use them both interchangeably because we have transpilers that don't really care whether the browser supports them natively or not. but, while "require" has its roots in old coding style coming from CommonJS back to 2009, "import" is deriving its syntax from the widely accepted ES6 (ES2015) syntax. so you should use "import" for new projects and not "require".

提交回复
热议问题