Grunt从typescript源生成空文件

Grunt generates empty file from typescript source

本文关键字:文件 typescript Grunt      更新时间:2023-09-26

我正在使用grunt编译类型脚本,并从中生成一些.js文件。问题是,由于某种原因,我总是得到一个空文件,其中只有一行来自编译文件的引用。但is应该包含相当复杂的javascript模块。

Gruntfile.js:

module.exports = function (grunt) {
    grunt.initConfig({
        pkg: grunt.file.readJSON("package.json"),
        clean: {
            dist: { src: ["dist"], force: true }
        },
        copy: {
        },
        typescript: {
            base: {
                src: [
                    "AwesomeGrid/**/*.ts"
                ],
                //dest: "dist/grid-fp.js",
                dest: "dist",
                options: {
                    target: "es5"
                }
            }
        }
    });
    grunt.loadNpmTasks("grunt-contrib-clean");
    grunt.loadNpmTasks("grunt-typescript");
    grunt.registerTask("default", ["clean", "typescript:base"]);
};

package.json:

{
  "name": "FalsePositiveManagement",
  "version": "2.0.0-alpha",
  "private": true,
  "author": "Moravia s.r.o.",
  "license": "none",
  "devDependencies": {
    "grunt": "~0.4.5",
    "grunt-contrib-clean": "~0.6.0",
    "grunt-contrib-watch": "~0.6.1",
    "grunt-typescript": "^0.8.0"
  }
}

源.ts文件:

    ///<reference path="../../typings/tsd.d.ts"/>
    module Fp {
        export interface IGroupSettings {
            key: string;
            title: string;
            icon: string;
            url: string;
            active: boolean;
        }
        export interface IFPGridTableSettings {
            tableElement: JQuery;
            gridOptions: AwesomeGrid.IGridOptions;
        }

生成的.js文件:

///<reference path="../../typings/tsd.d.ts"/>

tsd.d.ts文件:

    /// <reference path="jquery/jquery.d.ts" />
    /// <reference path="bootstrap/bootstrap.d.ts" />
    /// <reference path="chance/chance.d.ts" />
    /// <reference path="moment/moment.d.ts" />
    /// <reference path="grid/grid.d.ts" />
    /// <reference path="jasmine/jasmine.d.ts"/>

我对此很陌生,但它认为grunt应该从引用的文件中获取代码,并将其编译到target.js文件中,但它没有。它只是生成具有引用行的文件。。。

Typescript中的接口没有编译成JS代码,因为没有相应的JS代码构造。

从给定的TS代码(接口声明)中,您可以只获得".d.TS"文件-typescript定义。

变量、函数、类会产生一些JS代码。