[Typescript] "script" vs "module"

Typescript check a file whether it contains any export/import, if it is, then it's a module; if not then it's a script.

What's the difference between module vs script?

Script

Any variable and function declared inside script will be globally available.

Module

Any variable and function devlared inside module is scoped to it's file.

 

How to force Typescript to treat every file as moudle?

In tsconfig.json, we can enable "moduleDetection": "force"

posted @ 2024-08-07 19:04  Zhentiw  阅读(4)  评论(0编辑  收藏  举报