question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`getObject()` for Yup reports types of DefinitelyTyped

See original GitHub issue

Hi @Haroenv and other maintainers 👋 Hope you are well! Thanks again for your continued effort on the projects in the Algolia ecosystem!

I’m not sure if I’m reporting this in the right place, but I wanted to reach out about what appears to be a data problem with npm-search index (we’ve only seen a single library so far):

Running index.getObject() with the package name yup returns the following:

{
  types: {
    ts: 'definitely-typed',
    definitelyTyped: '@types/yup',
  },
}

However, on the npm website, the yup package is reported as having built-in types and the @types/yup package has been deprecated:

Screenshot 2022-12-05 at 19 58 19 Screenshot 2022-12-05 at 19 59 46

Both the current version and the beta version of yup have no "types" or "typings" keys in the package.json:

For the current yup@0.32.11, there is however no index.d.ts in the root:

But there is one in yup@1.0.0-beta.8:

Is the npm website or Algolia’s index wrong? (seems like npm website is wrong 🤔)


Our usage:

const client = algoliasearch(
  'XXX',
  'xxxxxxxxxxx',
);

const index = client.initIndex('npm-search');

const results = await index.getObject<AlgoliaObj>(dependency, {
  attributesToRetrieve: ['types'],
});

const definitelyTypedPackageName = results.types?.definitelyTyped;

https://github.com/upleveled/preflight/blob/5af8a398ec370c79e22ab770307ec81d574c8e29/src/checks/noDependencyProblems/noDependenciesWithoutTypes.ts#L63-L67

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:19 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
Josehowercommented, Dec 6, 2022

I already tested the solution from @jablko and it seems to work fine

https://github.com/algolia/npm-search/issues/1089#issuecomment-1339544822

image

if @Haroenv approves I can create the PR in no time

2reactions
jablkocommented, Dec 6, 2022

I think the TypeScript compiler will look for a bundled .d.ts file first, before an @types/package, so maybe this logic should be reversed: https://github.com/algolia/npm-search/blob/d99c31fbe733953d39e498f9c7d982b2e09f3458/src/typescript/index.ts#L69-L87

I.e. if a package both contains built-in TypeScript declarations and a @types/package exists, the built-in declarations should take precedence.

Read more comments on GitHub >

github_iconTop Results From Across the Web

types/yup: How to strongly-type ObjectSchema · Issue #29412
I'm using yup with Formik in my React app which I've written in Typescript. I have the following FormikProps interface: export interface ...
Read more >
Top 5 yup Code Examples - Snyk
Learn more about how to use yup, based on yup code examples created from the most popular ways it is used in public...
Read more >
How to use yup's object.shape with typescript? - Stack Overflow
I'm currently converting a piece of code to TypeScript and running into a few type issues with yup ...
Read more >
types/yup/index.d.ts - UNPKG
The CDN for @types/yup. ... 18, // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped ... 98, notRequired(): MixedSchema<T | undefined, C>;.
Read more >
yup-type-support - NPM Package Overview - Socket.dev
A typescript support for yup. Able to infer the yup schema from a typescript interface. Version: 1.0.6 was published by znaaron.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found