繁体   English   中英

如何在angular cli项目中使用@ types / fhir

[英]How do I use @types/fhir in angular cli project

当我将这个库安装到我的cli项目中并尝试引用其中的类型时,我得到了这个:

 error TS2306: File 'C:/ng-ikr-lib-test/node_modules/@types/fhir/index.d.ts' is not a module.

这是我的tsconfig:

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ]
  }
}

和我的应用程序tsconfig扩展了上述内容。

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "module": "es2015",
    "types": ["fhir"]
  },
  "exclude": [
    "src/test.ts",
    "**/*.spec.ts"
  ]
}

您如何在angular-cli应用程序中使用此库中定义的类型?

https://www.npmjs.com/package/@types/fhir

如果其他人偶然发现了这个问题,我将这个库的重新打包版本发布到公共npm注册表中。 你可以在这里找到它:

https://www.npmjs.com/package/fhir-stu3

干杯。

我发现最简单的方法是在文件顶部引用以下行的类型:

///<referencepath="../../../node_modules/@types/fhir/index.d.ts"/>

例如,我的fhir.service.ts文件顶部的引用如下所示:

///<reference path="../../../../node_modules/@types/fhir/index.d.ts"/>
import {Injectable} from '@angular/core';
import {Observable, throwError} from 'rxjs';
import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http';

import Patient = fhir.Patient;
import Observation = fhir.Observation;
import Bundle = fhir.Bundle;
import Medication = fhir.Medication;

您可以在“消费依赖关系”部分的https://www.typescriptlang.org/docs/handbook/declaration-files/library-structures.html上找到更多背景信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM