将js文件导入ts文件

时间:2019-05-31 17:53:45

标签: javascript typescript import

我已经阅读了有关此的几篇文章。我的方法昨天有效,但今天却失败了。我正在将js文件导入ts文件。 IF OBJECT_ID('tempdb..##A') IS NOT NULL DROP TABLE ##A IF OBJECT_ID('tempdb..#table1') IS NOT NULL DROP TABLE #table1 Create table #Table1 ( ControlNo INT, Bound INT, Declined INT, Rated INT, Quoted INT, QuoteStatus VARCHAR(50) ) INSERT INTO #Table1 (ControlNo, Bound, Declined, Rated, Quoted, QuoteStatus) VALUES (1111,1,0,1,1,'Lost'), (2222,0,1,0,1,'No Action'), (3333,1,1,0,0,NULL), (4444,1,0,0,1,'Lost'), (5555,0,1,1,1,'No Action') DECLARE @columns AS NVARCHAR(MAX), @finalquery AS NVARCHAR(MAX); SET @columns = STUFF((SELECT distinct ',' + QUOTENAME(QuoteStatus) FROM #Table1 FOR XML PATH(''), TYPE ).value('.', 'NVARCHAR(MAX)') ,1,1,'') --PRINT @columns set @finalquery = ' select p.controlno, p.Bound, p.Declined, p.Rated, p.Quoted,' + @columns + ' into ##A from ( select ControlNo, Bound, Declined, Rated, Quoted, QuoteStatus from #Table1 )a pivot ( COUNT(QuoteStatus) for QuoteStatus IN (' + @columns + ') )p ' exec(@finalquery) --SELECT * --FROM ##a DECLARE @colsUnpivot AS NVARCHAR(MAX), @query AS NVARCHAR(MAX) select @colsUnpivot = stuff((select ','+quotename(C.name) FROM tempdb.sys.columns c WHERE c.object_id = OBJECT_ID('tempdb..##A') for xml path('')), 1, 1, '') --PRINT @colsUnpivot set @query = 'select ControlNo, Counts, Status from ##A unpivot ( Counts for Status in ('+ @colsunpivot +') ) u' exec sp_executesql @query; 中的allowJs设置为true

出现以下错误:

tsconfig.json

input-parser.service.ts:

ERROR in src/app/core/input-parser.service.ts(5,26): error TS2497: Module '".../dashboard/shared/models/ecn-info"' resolves to a non-module entity and cannot be imported using this construct.

ecn-info.js:

import * as EcnInfo from '../../../../shared/models/ecn-info';

1 个答案:

答案 0 :(得分:0)

  1. export文件中使用ecn-info.js
export class EcnInfo {
    constructor(name, structure, status) {
        this.name = name;
        this.structure = structure;
        this.status = status;
    }
}
  1. 在您的noImplicitAny中禁用tsconfig.json
{
  "compilerOptions": {
    "noImplicitAny": false
    ...
  }
}
  1. 这样导入:
import EcnInfo from '../../../../shared/models/ecn-info';