Questions tagged [ts-check]

10 questions
10
votes
3 answers

Type assert an element in a JS file with @ts-check

I have a JS file with a // @ts-check directive, using JSDoc comments to denote types. The problem is that the elements fail type checks when retrieved from the document. So we have in HTML: ... When I get this element in JS the…
Keith
  • 150,284
  • 78
  • 298
  • 434
5
votes
1 answer

How to use @ts-check in VS Code across multiple files with non-module-based website?

I'm trying to create a really simple website with: A few JavaScript files that are directly included in the index.html No modules / import statements No bundling system or direct compilation step No requirement for a server to be run (so index.html…
Joseph Humfrey
  • 2,974
  • 2
  • 23
  • 34
3
votes
1 answer

How to use @template in function JSDoc to create coherence between param and return type?

I use @ts-check and ts linter on an ecmascript projet (I cannot use typescript but want its formalism). All is going well except for one thing: I want to use JSDoc generics declaration so that return type is tied-to/inferred-from a parameter…
TrogloGeek
  • 111
  • 5
2
votes
1 answer

VS Code @ts-check in JavaScript file not checking all things - nonexistent property not erroring

// @ts-check const obj = { str: `a string`, }; console.log(obj.nonexistant); // no error (it should be erroring) let num = 0; // type number num = obj.str; // has error (good) Why is the first issue not showing the red underline error/problem…
700 Software
  • 85,281
  • 83
  • 234
  • 341
2
votes
1 answer

How to tell JSDoc that a method returns an object containing a class type?

I have a Node.js function to create an Express server. I've added //@ts-check to the file so that VSCode lints and type-checks everything. What is the correct way to document this createServer function? I want to show that it returns a Promise…
d-_-b
  • 21,536
  • 40
  • 150
  • 256
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…
0
votes
0 answers

Make "ts-check" and "jsdoc" know about types defined in an IIFE

"Exporting" a type from an old style js module. How can I achieve ts-check and jsdoc compatibility when working with an old-style JavaScript module that selectively exports classes through this.ClassName = ClassName as shown below? We have a project…
T Ledt
  • 1
  • 2
0
votes
2 answers

//@ts-check and DOM element properties gives an error

I've got some simple browser-side JS code, and thought I'd try using @ts-check to pick out any fluff. Some valid bugs were found, and I've added js-doc parameter type information as well. I don't want a transpile step so this needs to be vanilla…
Roddy
  • 66,617
  • 42
  • 165
  • 277
0
votes
0 answers

javascript variable cannot been redeclared but cannot been accesed, too

I'm a newcomer in Javascript. I have two files with js code. file a.js contains const words = ["Alpha", "Bita", "Gama"]; console.log(words); file b.js contains //@ts-check const words = ["Alpha", "Bita", "Gama"]; console.log(words); Both a.js and…
Lefteris
  • 11
  • 3
0
votes
0 answers

ES6 inherited function returns wrong type when invoked on subclass

When a function is inherited by a subclass, I want the return type to be as if the function were defined directly on the subclass. To be clear, the code works fine at run-time. But I want to take advantage of static type-checking. I'm getting red…
phatpaul
  • 166
  • 7