Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript support? #322

Open
kamilszewczyk0 opened this issue Apr 1, 2021 · 6 comments
Open

TypeScript support? #322

kamilszewczyk0 opened this issue Apr 1, 2021 · 6 comments

Comments

@kamilszewczyk0
Copy link

Is library compatible with TypeScript? Any extensions for types?

@valepu
Copy link

valepu commented Jun 25, 2021

There is a bit of a problem with the @types.
The DefinitelyTyped package for is_js seems to be @types/is (i have tried @types/is_js @types/is-js @types/is.js @types/isjs but they don't exist), and the method calls seem correct, but if i import it like this:

import * as is from 'is_js';

i get an error saying it can't find the type definition when building (despite VS code not giving me any error). if i import it like this

import * as is from 'is';

I get a different error. The solution seems to be to install is_js with an alias: "is": "npm:is_js@^0.9.0", and then import the module like this import * as is from 'is';

if i do like this it seems to work but maybe i'm doing something completely wrong

@shivam-tripathi
Copy link

@valepu https://www.npmjs.com/package/is and https://www.npmjs.com/package/is_js are two entirely different libraries.

@valepu
Copy link

valepu commented Oct 7, 2021

@valepu https://www.npmjs.com/package/is and https://www.npmjs.com/package/is_js are two entirely different libraries.

@shivam-tripathi Yes, but the types are for is_js despite being called @types/is.
I can confirm this because the function is.existy is available in "is_js" but not in "is". On top of that if you check the file https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/is/index.d.ts you can read the following

// Type definitions for is.js
// Project: http://arasatasaygin.github.io/is.js/
// Definitions by: Rodrigo Cabral <https://github.com/cabralRodrigo>, Mitchell Grice <https://github.com/gricey432>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

@lancedolan
Copy link

To illustrate that @valepu is correct and there is a mismatch here:

  1. navigate to https://www.npmjs.com/package/@types/is
  2. Read :

    This package contains type definitions for is.js (http://arasatasaygin.github.io/is.js/).

  3. navigate to http://arasatasaygin.github.io/is.js
  4. click "View On Github", navigates to https://github.com/arasatasaygin/is.js
  5. Notice that the package name used in the readme directions is is_js

@lancedolan
Copy link

lancedolan commented Dec 1, 2022

Well I buckled and switched from is_js to is purely for easy typescript support, though I preferred the is_js api.

Also type definitions in @types/is aren't typeguard-friendly. I believe should be (x:unknown) : x is string and not (x:unknown) : boolean. Might log issue in that repo.

@lancedolan
Copy link

Update: I discovered that @types/is exports their types for both modules is and is_js.

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/is/index.d.ts#L1377-L1383

That can't be right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants