For anyone who wants eslint
typecheck without actually using typescript
, read this. I've been using this on my project to track any complicated data structure and it's been working perfectly. It supports both autocompletion and type lint. and it compiles without any performance drop as it doesn't affect the actual compilation. you don't need a complicated setup, just put *.d.ts
file on your work directory.
- https://fettblog.eu/typescript-jsdoc-superpowers/
- https://ricostacruz.com/til/typescript-jsdoc
- https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html
the only downside of this, is that type conversion is awkward in this method.(the type conversion still does work though) I think the community should invent newer style of JSDOC and IDEs should support it: something similar to above(typescript + JSDOC
) and leaner.
action.types.d.ts
export interface sayHelloArg {
(msg: string, type: string): boolean;
}
export const sayHello: sayHelloArg;
export as namespace Actions;
usage
// @ts-check
/// <reference path="./action.types.d.ts" />
/** @type {Actions.sayHello} */
const sayHello(msg, type) {
console.log(msg, type);
return true;
}
type conversion
const greeting = (/** @type {Actions.sayHello} */(anotherFunction));