Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Typescript中第三方模块的声明文件_Node.js_Typescript_Node Modules_Newrelic_Typescript Typings - Fatal编程技术网

Node.js Typescript中第三方模块的声明文件

Node.js Typescript中第三方模块的声明文件,node.js,typescript,node-modules,newrelic,typescript-typings,Node.js,Typescript,Node Modules,Newrelic,Typescript Typings,我在集成刚刚为第三方包“”创建的声明文件时遇到了一些问题。每次运行tsc时,我都会收到下一条错误消息: src/Server.ts(17,7): error TS2322: Type '{ express: typeof e; newrelic: typeof 'newrelic'; }' is not assignable to type 'BootServicesInterface'. “newrelic”属性的类型不兼容。 类型“typeof”newrelic“”不可分配给类型“newr

我在集成刚刚为第三方包“”创建的声明文件时遇到了一些问题。每次运行
tsc
时,我都会收到下一条错误消息:

src/Server.ts(17,7): error TS2322: Type '{ express: typeof e; newrelic: typeof 'newrelic'; }' is not assignable to type 'BootServicesInterface'.
“newrelic”属性的类型不兼容。 类型“typeof”newrelic“”不可分配给类型“newrelic”。 类型“typeof”newrelic“”中缺少属性“setTransactionName”

有人知道如何修复此错误吗?我已经为此工作了好几个小时,我看不出我做错了什么。源文件:

./src/Server.ts ./src/Core/Boot.ts ./@CustomTypes/newrelic/index.d.ts: /tsconfig.json
我忘了自己导出函数。当然,我制作了newrelic接口,但是忘记了导出函数本身。正确的声明文件应为:

./@CustomTypes/newrelic/index.d.ts:
您将newrelic的类型声明为newrelic.newrelic,所以您应该通过newrelic.newrelic,而不是newrelic。像这样
const-Services:BootServicesInterface={express,newrelic:newrelic.newrelic,}
@niba谢谢你的回答。它没有解决问题,但它给了我正确的方向。
'use strict'

import * as debugDep from 'debug'
const debug = debugDep('server')
debug('Booting Server')

debug('Loading .env file')
import * as dotenv from 'dotenv'
dotenv.config({silent: true})

debug('Loading System Dependencies')
import * as express from 'express'
import * as newrelic from 'newrelic'
import {BootClass, BootServicesInterface} from './Core/Boot'

debug('Setup Webserver')
const Services: BootServicesInterface = {
  express,
  newrelic,
}

const boot = new BootClass(Services)
'use strict'
import * as express from 'express'
import * as newrelic from 'newrelic'

export interface BootClassInterface {
  setup(): express.Express
}

export interface BootServicesInterface {
  newrelic: newrelic.newrelic
  express(): express.Express,
}

export class BootClass implements BootClassInterface {

  private services: BootServicesInterface

  public constructor(services: BootServicesInterface) {
    this.services = services
  }

}
declare module 'newrelic' {
    export interface newrelic {
      setTransactionName: (name: string) => void,
      setControllerName: (name: string, action?: {}) => void,
      createWebTransaction: (url: string, handler: Function) => void,
      createBackgroundTransaction(name: string, group: string | null | undefined, handler: Function): void,
      createBackgroundTransaction(name: string, handler: Function): void,
      endTransaction: () => void,
      createTracer: (name: string, callback: Function) => void,
      recordMetric: (name: string, value: number | {count: number, total: number, min: number, max: number, sumOfSquares: number}) => void,
      incrementMetric: (name: string, amount?: number) => void,
      recordCustomEvent: (eventType: string, attributes: {}) => void,
      addCustomParameter: (name: string, value: string | number) => void,
      addCustomParameters: (params : {}) => void,
      getBrowserTimingHeader: () => string,
      setIgnoreTransaction: (ignored: boolean) => void,
      noticeError: (error: Error, customParameters?: {}) => void,
      shutdown(options: Options, callback: Function): void,
      rules: Rules,
      addNamingRule: (pattern: Pattern[], name: string) => void,
      addIgnoringRule: (pattern: string[]) => void,
    }

    export interface Rules {
      name: Pattern[],
      ignore: string[],
    }

    export interface Pattern {
      pattern: string, 
      name: string, 
      terminate_chain?: boolean, 
      replace_all?: boolean, 
      precedence?: boolean
    }

    export interface Options{
      collectPendingData: boolean,
      timeout: number
    }
}
{
    "compilerOptions": {
        "module": "es6",
        "moduleResolution": "node",
        "noImplicitAny": true,
        "noImplicitReturns": true,
        "noImplicitThis": true,
        "noUnusedLocals": true,
        "noUnusedParameters": true,
        "removeComments": false,
        "skipLibCheck": false,
        "sourceMap": false,
        "strictNullChecks": true,
        "target": "ES2016",
        "outDir": "./lib",
        "declaration": true,
        "diagnostics": true,
        "alwaysStrict": true
    },
    "exclude": [
        "node_modules",
        "public"
    ],
    "include": [
        "**/*.d.ts",
        "./src/**/*.ts"
    ],
    "typeRoots": [
        "@CustomTypes",
        "node_modules/@types"
    ],
    "lib": [
        "es6"
    ]
}
declare module 'newrelic' {

  export interface Rules {
    name: Pattern[],
    ignore: string[],
  }

  export interface Pattern {
    pattern: string, 
    name: string, 
    terminate_chain?: boolean, 
    replace_all?: boolean, 
    precedence?: boolean
  }

  export interface Options{
    collectPendingData: boolean,
    timeout: number
  }

  export interface MetricValue{
    count: number, 
    total: number, 
    min: number, 
    max: number, 
    sumOfSquares: number
  }

  export interface newrelic { 
    setTransactionName(name: string): void
    setControllerName(name: string, action: {}): void
    setControllerName(name: string): void
    createWebTransaction(url: string, handler: Function): void
    createBackgroundTransaction(name: string, group: string| null, handler: Function): void
    createBackgroundTransaction(name: string, handler: Function): void
    endTransaction(): void
    createTracer(name: string, callback: Function): void
    recordMetric(name: string, value: number | MetricValue): void
    incrementMetric(name: string, amount?: number): void
    recordCustomEvent(eventType: string, attributes: {}): void
    addCustomParameter(name: string, value: string | number): void
    addCustomParameters(params : {}): void
    getBrowserTimingHeader(): string
    setIgnoreTransaction(ignored: boolean): void
    noticeError(error: Error, customParameters: {}): void
    noticeError(error: Error): void
    shutdown(options: Options, callback: Function): void
    rules: Rules
    addNamingRule(pattern: Pattern[], name: string): void
    addIgnoringRule(pattern: string[]): void
  }

  export function setTransactionName(name: string): void
  export function setControllerName(name: string, action: {}): void
  export function setControllerName(name: string): void
  export function createWebTransaction(url: string, handler: Function): void
  export function createBackgroundTransaction(name: string, group: string| null, handler: Function): void
  export function createBackgroundTransaction(name: string, handler: Function): void
  export function endTransaction(): void
  export function createTracer(name: string, callback: Function): void
  export function recordMetric(name: string, value: number | MetricValue): void
  export function incrementMetric(name: string, amount?: number): void
  export function recordCustomEvent(eventType: string, attributes: {}): void
  export function addCustomParameter(name: string, value: string | number): void
  export function addCustomParameters(params : {}): void
  export function getBrowserTimingHeader(): string
  export function setIgnoreTransaction(ignored: boolean): void
  export function noticeError(error: Error, customParameters: {}): void
  export function noticeError(error: Error): void
  export function shutdown(options: Options, callback: Function): void
  export var rules: Rules
  export function addNamingRule(pattern: Pattern[], name: string): void
  export function addIgnoringRule(pattern: string[]): void
}