Is it possible to show a custom typescript error in VS code when an interface is used improperly?

Viewed 72

I am trying to explain to myself (in the future lol) how exactly a function should be implemented, It would be nice if I could get the UI to tell me what EXACTLY I need to return instead of what I shouldn't return. Given:

type ruleFunction = (this: Rule, dev: Developer) => 'submitResultsFunction'

const foo: ruleFunction = (dev: Developer) => {} 

currently shows: "Type '(this: Rule, dev: Developer => void' is not assignable to type 'ruleFunction'

I would like to replace that text with 'function must return 'submitResultsFunction'

1 Answers

You can use jsdoc notation. For example

type Fn = (arg: number) => string

/**
 * 
 * @description Function do something
 * @returns {string} Fn must return `sdf` string
 */
const myFunction: Fn = (arg) => 'sdf'

When you hover mouse on the myFunction, You will see VS code tooltip.

Documentation for jsdoc in typescript here

Related