<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                [TOC] ## 聲明文件 - 當使用第三方庫時,我們需要引用它的聲明文件,才能獲得對應的代碼補全、接口提示等功能。 - 通常我們會把聲明語句放到一個單獨的文件(`jQuery.d.ts`) - 一般第三方都有自己的聲明文件,可使用如 `npm install @types/jquery --save-dev `的方式下載聲明文件 ## 語法 * [`declare var`](https://ts.xcatliu.com/basics/declaration-files.html#declare-var)聲明全局變量 * [`declare function`](https://ts.xcatliu.com/basics/declaration-files.html#declare-function)聲明全局方法 * [`declare class`](https://ts.xcatliu.com/basics/declaration-files.html#declare-class)聲明全局類 * [`declare enum`](https://ts.xcatliu.com/basics/declaration-files.html#declare-enum)聲明全局枚舉類型 * [`declare namespace`](https://ts.xcatliu.com/basics/declaration-files.html#declare-namespace)聲明(含有子屬性的)全局對象 * [`interface`和`type`](https://ts.xcatliu.com/basics/declaration-files.html#interface-%E5%92%8C-type)聲明全局類型 * [`export`](https://ts.xcatliu.com/basics/declaration-files.html#export)導出變量 * [`export namespace`](https://ts.xcatliu.com/basics/declaration-files.html#export-namespace)導出(含有子屬性的)對象 * [`export default`](https://ts.xcatliu.com/basics/declaration-files.html#export-default)ES6 默認導出 * [`export =`](https://ts.xcatliu.com/basics/declaration-files.html#export-1)commonjs 導出模塊 * [`export as namespace`](https://ts.xcatliu.com/basics/declaration-files.html#export-as-namespace)UMD 庫聲明全局變量 * [`declare global`](https://ts.xcatliu.com/basics/declaration-files.html#declare-global)擴展全局變量 * [`declare module`](https://ts.xcatliu.com/basics/declaration-files.html#declare-module)擴展模塊 * [`/// <reference />`](https://ts.xcatliu.com/basics/declaration-files.html#san-xie-xian-zhi-ling)三斜線指令 ## 技巧 ## 自動生成聲明文件 如果庫的源碼本身就是由 ts 寫的,那么在使用`tsc`腳本將 ts 編譯為 js 的時候,添加`declaration`選項,就可以同時也生成`.d.ts`聲明文件了 tsconfig.json ``` { "compilerOptions": { "module": "commonjs", "outDir": "lib", "declaration": true, } } ``` **發布聲明文件§** 此時有兩種方案: 1. 將聲明文件和源碼放在一起-推薦 2. 將聲明文件發布到 @types 下 ### 將聲明文件和源碼放在一起 方式一: 如果聲明文件是通過`tsc`自動生成的,那么無需做任何其他配置,只需要把編譯好的文件也發布到 npm 上 方式二: * 給`package.json`中的`types`或`typings`字段指定一個類型聲明文件地址 * 在項目根目錄下,編寫一個`index.d.ts`文件 * 針對入口文件(`package.json`中的`main`字段指定的入口文件),編寫一個同名不同后綴的`.d.ts`文件
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看