【问题标题】:How do I use @types/fhir in angular cli project如何在 Angular cli 项目中使用 @types/fhir
【发布时间】:2018-08-02 20:38:24
【问题描述】:

当我将这个库安装到我的 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

【问题讨论】:

  • 愿意提供拒绝投票的理由吗?
  • 我想知道,你也需要安装this 吗?通常,您需要库和类型。我从来没有使用过这个库,所以这是一个猜测。文档似乎对这个主题有点了解。

标签: angular hl7-fhir


【解决方案1】:

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

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

干杯。

【讨论】:

  • 谢谢!这对我们这些在 Angular 中处理 FHIR 响应的人非常有帮助。非常感谢!
  • 不客气,很高兴我能帮上忙。我知道这个问题让我发疯了一段时间。
【解决方案2】:

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

///<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 的“使用依赖项”部分下找到更多背景信息。

【讨论】:

  • 谢谢,看来这归结为库作者打包这个库的风格。它被打包为一个全局库,因此需要 /// 引用 nasties。我最终重新打包了这个库,这样它就不会在全局范围内运行。谢谢!
  • @cobolstinks 你重新打包的库在 npm 上可用吗?
  • @Brandon 它位于内部工件存储库中......我将不得不查看许可证,看看是否可以将重新打包的库发布到公共 npm 注册表。
  • @cobolstinks 如果可能的话会非常有用
  • @Brandon 它是 MIT,所以我应该没问题,我今晚会尝试发布它。
猜你喜欢
  • 1970-01-01
  • 2017-08-27
  • 2017-05-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-08
  • 2022-01-04
  • 2020-10-15
相关资源
最近更新 更多