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

ts7016 error - cannot resolve types between index.d.ts and package.json #94

Open
sxflynn opened this issue Jun 16, 2024 · 2 comments
Open

Comments

@sxflynn
Copy link

sxflynn commented Jun 16, 2024

I performed an npm install aa-js into my Typescript project and VS Code is giving this linting error on the import statement.

I followed the example in the readme and started by importing julian days.

import { juliandays, Earth } from 'aa-js'

const jd = juliandays.getJulianDay(new Date())

Under the 'aa-js' it provides an error and this is the message:

Could not find a declaration file for module 'aa-js'. '/[appname]/node_modules/aa-js/dist/aa-js.js' implicitly has an 'any' type. There are types at '[appname]/node_modules/aa-js/dist/index.d.ts', but this result could not be resolved when respecting package.json "exports". The 'aa-js' library may need to update its package.json or typings. ts(7016)

For example, this code does work:

import {
  Sun,
  coordinates,
  type JulianDay,
  GeographicCoordinates,
  HorizontalCoordinates,
  EquatorialCoordinates,
} from "aa-js";

export const calcSunAltitude = (
  jd: JulianDay,
  coord: GeographicCoordinates
): HorizontalCoordinates => {
  const sunGeoEquCoord: EquatorialCoordinates =
    Sun.getGeocentricEquatorialCoordinates(jd);
  return coordinates.transformEquatorialToHorizontal(jd, sunGeoEquCoord, coord)
    .altitude;
};

Although I am able to compile and run the web application with this error, I am not provided with any Typescript intellisense or typechecking.

@sxflynn
Copy link
Author

sxflynn commented Jun 18, 2024

Update:

In my tsconfig.json file I manually pointed to the aa-js directory in node_modules and this resolved the error.

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "aa-js": ["node_modules/aa-js/dist/index.d.ts"]
    },
// rest of options
   }
}

That being said, this should not be necessary. The package.json in the aa-js package needs to be modified so that it can point to types without the consumer modifying their local configuration.

@onekiloparsec
Copy link
Owner

Thank you very much for your bug report. I must admit I always had a very hard time understanding how to configure TS! Seriously, I read many articles, and the official documentation, but I always got lost.

I totally agree with your conclusion: this should not be necessary. However, I have no idea how to solve it.

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

2 participants