Categories
Mastering Development

Property ‘toBeInTheDocument’ does not exist on type ‘Matchers

Trying to setup testing for a components library. I’ve tried many example and all similar threads on this with no luck. My setupTests.ts file is correctly being loaded (proven with a console.log), and the library seems to be available as if I add import { toBeInTheDocument } from ‘@testing-library/jest-dom/matchers’ and log toBeInTheDocument it is present. […]

Categories
Mastering Development

tsconfig path cannot be found

I am working on a nodejs app and I want to configure my path in tsconfig.json but I am having issues with the path configuration I keep getting an error Error: Cannot find module ‘@environment’. what could be the issue? tsconfig { “compilerOptions”: { “resolveJsonModule” : true, “target”: “es6”, “module”: “commonjs” , “lib”: [ “dom”, […]

Categories
Development

How to stop TypeScript error ‘Type A has no properties in common with Type B’ when Type B “extends” Type A in some way

(edited Title to make more general) I’m working in a codebase which uses React class components and Typescript everywhere, and I’m trying to implement react-dropzone (a lightweight, simple but effective file-drop component) using the class-based method. The Hooks implementation is cleaner and simpler but I’d prefer to avoid so as to preserve the paradigm maintained […]

Categories
Development

“An accessor cannot be declared in an ambient context.” in a custom library

I have a webpack, typescript project (A) which emits a small library. The library is used in an angular 8 project (B). In project A I declare a class like: export class Foo { private foo: string; constructor(foo: string) { this.foo = foo; } } export class Bar extends Foo { private bla: string; constructor(foo: […]

Categories
Development Plugins XML

Visual Studio Code incorreclty reporting error ‘Cannot find module’ when importing XML file, whilst this error doesn’t appear on build

I’m writing a Typescript testcase, which needs some static xml, loaded from an file which is part of the project. I’m using webpack, in a node/typescript project and am finding that VSC typescript is out of step with the project’s typescript. The line which is causing a problem (from VSC perspective) is this (the testcase […]

Categories
Development

typescript cannot find module when import svg file

It’s web application created with Typescript, React and webpack. I want to use svg file through webpack. However, I got TS2307: Cannot find module ‘~/images/slide.svg’. Typescript files are put on /frontend/src/, and typescript files are build successfully. Then, I tried some solutions on website. But I could not solve this problem. What I tried is […]

Categories
Development

Typescript cannot find module defined in paths

I have a typescript application that has paths for absolute imports. My tsconfig looks like this: { “compilerOptions”: { “baseUrl”: “.”, “paths”: { “utils*”: [“src/utils*”], “operations*”: [“src/operations*”], “actions*”: [“src/actions*”], “components*”: [“src/components*”], “constants*”: [“src/constants*”], }, “outDir”: “dist”, “module”: “esnext”, “target”: “esnext”, “moduleResolution”: “node”, “noEmit”: true, “lib”: [“es2017”, “dom”], “noUnusedLocals”: true, “sourceMap”: true, “skipLibCheck”: true, “allowJs”: true, […]

Categories
Development

Error using ES Module import for object-set-all-values-to

In an Angular 6 project I’m trying to use the npm package object-set-all-values-to 3.9.45. I did the following: 1- Installed it using npm i object-set-all-values-to OK 2- Tried to import it Error 1st option import setAllValuesTo from ‘object-set-all-values-to’; Could not find a declaration file for module ‘object-set-all-values-to’. ‘<my-project-path>/node_modules/object-set-all-values-to/dist/object-set-all-values-to.cjs.js’ implicitly has an ‘any’ type. Try `npm […]

Categories
Development

jest test does not recognize typescript syntax

I have a sample nodejs project which is a Google Pubsub Cloud Functions sample where I am trying out Jest as the testing tool. When I am running npm script to do the unit test I get an error that indicates that typescript is not being recognized. I am doing just npm run test:unit that […]

Categories
Development

How to import submodule from a ts file

I want to import a submodule from a ts file into my project. The problem is that the output file includes the entire imported file and not only the imported object. I have an example.ts file with several exports: export enum e1{a, b} export enum e2{c, d} export class exampleclass { static f() { return […]