.d.ts

How to solve the “Could not find a declaration file for module” error using my own declaration file?

∥☆過路亽.° 提交于 2021-01-28 08:31:13
问题 I have a test project in which I'm testing type definition files. The project has one file called index.ts which looks like this: import i18nFu = require("gettext.js"); The gettext.js package was installed using Node.js like this: npm install gettext.js VS Code displays the following error message for the line above: Could not find a declaration file for module 'gettext.js'. 'SOME_PATH/gettext.js' implicitly has an 'any' type. Try 'npm install @types/gettext.js' if it exists or add a new

Accessing superclass properties from within a mixin with TypeScript declarations

走远了吗. 提交于 2020-03-05 07:35:22
问题 This is a follow up question to Using JavaScript Class Mixins with TypeScript Declaration Files Given a JavaScript Mixin: export function Mixin(superclass) { return class Consumer extends superclass { connectedCallback() { super.connectedCallback && super.connectedCallback(); this.mo = new MutationObserver(console.log) this.mo.observe(this) } classMethod() { return true } } } And a TypeScript declaration file: export declare class Consumer extends HTMLElement { public classMethod(): boolean }

Accessing superclass properties from within a mixin with TypeScript declarations

依然范特西╮ 提交于 2020-03-05 07:34:12
问题 This is a follow up question to Using JavaScript Class Mixins with TypeScript Declaration Files Given a JavaScript Mixin: export function Mixin(superclass) { return class Consumer extends superclass { connectedCallback() { super.connectedCallback && super.connectedCallback(); this.mo = new MutationObserver(console.log) this.mo.observe(this) } classMethod() { return true } } } And a TypeScript declaration file: export declare class Consumer extends HTMLElement { public classMethod(): boolean }

write a typescript .d.ts type definition down node_module folder

喜夏-厌秋 提交于 2020-02-02 13:43:24
问题 I need to write a .d.ts file for an external (npm) library. I am using typescript 3. The imports I need are: import fakedb from 'fake-indexeddb'; //sorted // second import I would like: import dbKeyRange from 'fake-indexeddb/lib/FDBKeyRange' from types/fake-indexeddb.d.ts: export = index; declare const index: IDBFactory; How do I write a file for the second import from the library I would like( fake-indexeddb/lib/FDBKeyRange - an IDBKeyRange )? Edit while the answer by Juraj Kocan is

Create react app typescript does not load d.ts file

梦想与她 提交于 2020-01-24 06:56:05
问题 I have created a project using create react app typescript. I have a few d.ts files where I have defined interfaces types and enums. When I run start script. It is not able to load the d.ts files. following is my tsconfig file. { "compilerOptions": { "target": "es6", "lib": [ "dom", "dom.iterable", "es2017" ], "allowJs": true, "skipLibCheck": false, "esModuleInterop": true, "allowSyntheticDefaultImports": true, "strict": false, "forceConsistentCasingInFileNames": true, "module": "esnext",

Add custom typings file in a JavaScript VSCode project

百般思念 提交于 2019-12-29 03:37:28
问题 Problem I am working on JavaScript project using VSCode. I am using the UMD design pattern and vscode intellisense cannot recognize the exports of a module from another file. I added all the declarations in a file called globals.d.ts . Unfortunately I couldn't find a way to load the globals.d.ts declarations from my JavaScript files. Example Module declaration export namespace ModuleName { export interface Item { toString(): string; property: string; name: string; } } Example JavaScript File

Declare Interfaces in typings file for JavaScript

佐手、 提交于 2019-12-19 05:56:44
问题 Project Info I'm working on a JavaScript project that utilizes .d.ts files. This is a subsequent question to a question I previously asked, so you can view more information regarding the project here. Problem Although I can normally extract functions from the typings files I can't extract interfaces or namespaces that are either empty or consist purely of interfaces. I have temporarily fixed this problem by creating a const implementation for each interface and using @typeof

Typescript does not copy d.ts files to build

给你一囗甜甜゛ 提交于 2019-12-12 10:59:27
问题 So maybe I'm confused, but I thought that if I added declaration:true to my tsconfig.json I could have it tsc copy my *.d.ts files, along side the transpiled code & it's d.ts files? EG: - src - lib - types.d.ts - foo.ts I would expect the result of tsc to be something like: - build - lib - types.d.ts - foo.js - foo.d.ts However, I can't seem to get types.d.ts to be copied to my build directory. Does typescript not provide any mechanism to copy .d.ts files? Or do I just have a misconfiguration

Using JavaScript Class Mixins with TypeScript Declaration Files

萝らか妹 提交于 2019-12-11 02:17:49
问题 I need help using class mixins in declaration files. Specifically, when a method is defined in a mixin, typescript is not picking it up in the mixed class body: In my case, I am applying two mixins. The first mixin - NotifyingElementMixin - provides a method called notify , and it's this method which is failing to apply to the mixed class body notifying-element-mixin.js export const NotifyingElementMixin = superclass => class NotifyingElement extends superclass { /** * Fires a `*-changed`