我如何在Angle CLI项目中使用@ types/fhir [英] How do I use @types/fhir in angular cli project

查看:67
本文介绍了我如何在Angle CLI项目中使用@ types/fhir的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When i npm install this library into my cli project and try to reference the types within it i get this:

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

这是我的tsconfig:

Here is my 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扩展了上面的内容.

and my app tsconfig which extends the above.

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

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

How are you supposed to use the types defined in this library in an angular-cli app?

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

推荐答案

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

The easiest way I've found is to reference the types with the following line at the top of your file:

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

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

For example, the references at the top of my fhir.service.ts file look like this:

///<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 在消费依赖项"部分下.

You can find out more background information at https://www.typescriptlang.org/docs/handbook/declaration-files/library-structures.html under the "Consuming Dependencies" section.

这篇关于我如何在Angle CLI项目中使用@ types/fhir的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆