1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

Angular creating library: Unable to use 3rd party package types

Discussão em 'Angular' iniciado por prusama, Setembro 27, 2024.

  1. prusama

    prusama Guest

    I am developing own library for voice recognition. I want to use 3rd party package types @types/dom-speech-recognition. When I tried to use the types in my service, the compiler was throwing errors that those 3rd party types cannot be found:

    Error: ../angular-voice-recognition/src/lib/voice-recognition.service.ts:9:23 - error TS2304: Cannot find name 'SpeechRecognition'.

    9 private speechAPI!: SpeechRecognition;
    ~~~~~~~~~~~~~~~~~


    Error: ../angular-voice-recognition/src/lib/voice-recognition.service.ts:40:28 - error TS2304: Cannot find name 'webkitSpeechRecognition'.

    40 this.speechAPI = new webkitSpeechRecognition();
    ~~~~~~~~~~~~~~~~~~~~~~~


    I've installed these types by npm install @types/dom-speech-recognition --save

    tsconfig.lib.json:

    {
    "extends": "../../tsconfig.json",
    "compilerOptions": {
    "outDir": "../../out-tsc/lib",
    "declaration": true,
    "declarationMap": true,
    "inlineSources": true,
    "types": [
    "dom-speech-recognition"
    ]
    },
    "exclude": [
    "src/test.ts",
    "**/*.spec.ts"
    ]
    }


    voice-recognition.service.ts:

    import { Injectable } from '@angular/core';
    import {VoiceParams} from "./model/voice-params.model";
    import {Observable} from "rxjs";
    import {VoiceResult} from "./model/voice-result";
    import {VoiceEvent} from "./model/voice-event";

    @Injectable()
    export class VoiceRecognitionService {
    private speechAPI!: SpeechRecognition;

    ...

    private initialize(params: VoiceParams) {
    if ('webkitSpeechRecognition' in window) {
    ...
    }
    }
    }


    These are all places which I modified after installing the @types/dom-speech-recognition into my library.

    Do I need to export or import the type also somewhere else?

    Continue reading...

Compartilhe esta Página