How to generate “*.d.ts” in TypeScript?

前端 未结 3 562
猫巷女王i
猫巷女王i 2021-01-24 07:52

How to generate “*.d.ts” in typescript or creates and import @types? Is there any way to create d.ts for jquery plugin or plain javascript library?

3条回答
  •  萌比男神i
    2021-01-24 08:16

    For your own code, this can be done with a compiler option:

    tsc --sourceMap=true
    

    This can also be added to your tsconfig file, as well as MSBuild task.

    For jQuery, most of those libraries are on DefinitelyTyped, where you can install them via @types/LIBRARY_NAME.

    For other third party libraries, you may have to create them yourself; otherwise, you can allow JavaScript with another compiler option:

    tsc --allowJs=true
    

    Then depending on your loading tool, you can use require or some other mechanism to import.

提交回复
热议问题