简体   繁体   中英

Where is this VSCODE intellisense coming from?

In VSCODE I see the following intellisense:

在此处输入图片说明

When exploring node_modules/sanctuary/index.js , I find a function toMaybe , but it doesn't appear the definition is coming from here because they do not match

//# toMaybe :: a? -> Maybe a
//.
//. Takes a value and returns Nothing if the value is `null` or `undefined`;
//. Just the value otherwise.
//.
//. ```javascript
//. > S.toMaybe (null)
//. Nothing
//.
//. > S.toMaybe (42)
//. Just (42)
//. ```

This is in contrast to other functions that commonly display like this:

在此处输入图片说明

Two questions:

  1. Where should I look next?
  2. How can I document my own functions like this?

UPDATE:

Lukas Bach and ippi have pointed out, one part, Sanctuary.Static.toMaybe<A>(p: A): Maybe<A> comes from the Automatic type acquisition feature.

Even after deleting all @types from ~/Library/Caches/typescript/2.9/node_modules/types-registry , I still see some docs.

在此处输入图片说明

I also was not able to find the text toMaybe :: a -> Maybe a in the @types/sanctuary/index.d.ts file or anywhere in the @types directory.

The programming language TypeScript, a superset of JavaScript, allows definitions for proper types on functions and variables. TypeScript can be compiled down to JavaScript, which removes all type annotations, and a seperate type definition file (*.d.ts) can be exported during transpiliation. TypeScript type definitions are nowadays commonly provided for JS modules either directly in the module repository itself or as part of the DefinitelyTyped repository.

To get such type annotations for your own code, you can either write your code in TypeScript in the first place or write additional custom type definition files by yourself.

This is not the only way to write type definitions, but at the moment the most prominent one.

Edit: Ok, I did not really look into the package that you've mentioned earlier. But I've tried it out, and this is the IntelliSense annotation, which it gives to me. VS屏幕截图

And this seems to be coming from the TS typing:

toMaybe<A>(p: A | null | undefined): Maybe<A>;

These typings are located at https://www.npmjs.com/package/@types/sanctuary .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM