Questions tagged [checkjs]

checkJs is a mode for checking JavaScript code using the TypeScript type system

10 questions
33
votes
3 answers

require a json file results in an error: Cannot find module

In a nodej project open in VsCode with checkJs enabled, when a json file is required like const myFile = require('./my-file.json') This makes an error [ts] Cannot find module. How is it possible to remove the error warning? I tried to: add…
François Romain
  • 13,617
  • 17
  • 89
  • 123
12
votes
0 answers

How to use custom typings in JS project

I'm working in an Electron project with checkjs: true set in my jsconfig.json and have created a file with custom typings in ProjectRoot/typings/index.d.ts. I'd like to have those typings available in all JS files. Unfortunately I have to reference…
suamikim
  • 5,350
  • 9
  • 40
  • 75
4
votes
1 answer

JSDoc Typescript Checking of Named Default Params

Given the following /** * @param {{bar?: string|null}} [param0] */ const foo = ({bar = null} = {}) => bar; Typescript 3.7.2 reports var bar: string | null Binding element 'bar' implicitly has an 'any' type.ts(7031) The JavaScript code works how I…
Paul Milham
  • 526
  • 5
  • 13
4
votes
1 answer

How do I override incorrect types from a package that ships its own .d.ts?

I am using chalk with a JavaScript project that I'm checking with TypeScript's checkJs flag. The JavaScript code imports it like so: const chalk = require('chalk') Unfortunately, chalk ships its own types, and its types are wrong. It should use the…
Nathan Shively-Sanders
  • 18,329
  • 4
  • 46
  • 56
1
vote
1 answer

TypeScript errors while using it for type-checking JavaScript code containing React components

I am using typescript for type checking my javascript code that has docstring type annotations. It worked fine until I started using React. There is no issue when I write my components as classes: export default class MyComponent extends…
dannymo
  • 390
  • 3
  • 13
1
vote
0 answers

Using @type for declare type of class method in JavaScript

When I use @type to declare type of class method in JavaScript with d.ts (see Type Checking JavaScript Files), the parameter types are determined incorrectly, if I use the short form of the method entry. If I use a form with function, everything…
1
vote
1 answer

with ts(2605) in VScode with checkJs enabled

I wanted to use JS type checking capability inside VScode. Everything works like charm but React.Fragment is linted with error: JSX element type 'ReactElement' is not a constructor function for JSX elements. Type 'ReactElement' is missing…
palci12
  • 179
  • 1
  • 3
  • 12
1
vote
0 answers

How to use classes from other module in JSDoc annotations

Best explained with an example: some-class.js function SomeClass() { /* ... */ } SomeClass.prototype.doSomething = function() { /* ... */ }; export function createSomeClass() { return new SomeClass(); } index.js import { createSomeClass }…
suamikim
  • 5,350
  • 9
  • 40
  • 75
0
votes
1 answer

How to annotate an ES5 class with a JSDoc @template in VSCode to prevent checkJS errors?

I am attempting to annotate all my JavaScript functions and class properties with JSDoc to enable proper type checking using TypeScript and the checkJS option. However, since I want to support older browsers (IE9), and I do not want to transpile the…
0
votes
1 answer

Exclude files from "checkJS"

Can I somehow exclude dedicated files from VSCodes setting "javascript.implicitProjectConfig.checkJs": true? I'd like to not have my webpack builds checked which are all placed in a dist folder. I know that I could add **/dist/* or **/dist to…
suamikim
  • 5,350
  • 9
  • 40
  • 75