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

spot doesn't seem to read tsconfig #1109

Open
ccakes opened this issue Nov 6, 2020 · 7 comments
Open

spot doesn't seem to read tsconfig #1109

ccakes opened this issue Nov 6, 2020 · 7 comments
Labels
enhancement New feature or request

Comments

@ccakes
Copy link

ccakes commented Nov 6, 2020

Describe the bug
It seems as though spot isn't using the local tsconfig.json, or for some other reason isn't loading locally-defined type declarations.

I'm experimenting with spot to generate OpenAPI docs for an existing Typescript project which uses a couple of un-typed javascript dependencies. I've written basic type declarations for them and configured tsconfig.json so that they're discovered. tsc has no problems but as soon as I try to import anything from a module that also includes one of these dependencies spot fails with this error.

The api/http also works with tsc because of an entry in paths but spot isn't recognising it

$ npx @airtasker/spot lint src/api/contract.ts
    Error: Could not find a declaration file for module 'snub'. 
    '/path/to/node_modules/snub/snub.js' implicitly has an 'any' type.
    Module '"/path/to/node_modules/@types/humps/index"' has no default export.
    Cannot find module 'api/http' or its corresponding type declarations.
    Invalid module name in augmentation. Module 'snub' resolves to an untyped module at 
    '/path/to/node_modules/snub/snub.js', which cannot be augmented.

To Reproduce
Here's a contrived pseudocode example

// file1.ts
import {foo} from 'untyped-module-with-local-typedefs';
import {HttpResponsePayloadExt} from 'api/http'; // path defined in tsconfig.json
                                                 // not used in the interface being introspected by spot at all

export interface ISomethingUseful {
  foo: string;
}

// contract.ts
import {ISomethingUseful} from 'file1';

@endpoint({method: 'POST', path: '/foo'})
class Request {
  @request
  request(@body body: ISomethingUseful)
}

Expected behavior
Ideally spot would resolve paths and type declarations in the same way that tsc does

Desktop (please complete the following information):

  • OS: macOS 10.15.7
  • npm version: 6.14.6
  • Node version: v12.18.3
  • Spot version: @airtasker/spot/1.2.0 darwin-x64 node-v12.18.3
@mahirk
Copy link
Contributor

mahirk commented Nov 12, 2020

Seem to be facing this issue as well and the way I had to fix it was to edit the compiler options directly in https://github.com/mahirk/spot/blob/47bd3ae433deeb3fbc234052ca575dc5d921b0d9/lib/src/parser.ts#L27-L46

Maybe it can either accept:

  1. Additional cli options
  2. Or an option to point to the tsconfig file.

@lfportal
Copy link
Contributor

I'm leaning towards allowing an optional option to point to a tsconfig file. @ccakes Spot has not been tested with external type definitions. I'll take a look at how we might be able to support this. However, at the moment Spot supports a rather strict subset of the TypeScript syntax. For example, many of TypeScript's utility types are currently not supported, so even it will likely not be a smooth ride for external type definitions unfortunately.

@ccakes
Copy link
Author

ccakes commented Nov 19, 2020

Yeah ok - that makes sense.

I kind of forgot that this isn't intended to be integrated into a Typescript project but it only uses a subset of TS 😅

An optional tsconfig pointer would be perfect

@lfportal lfportal added the enhancement New feature or request label Nov 20, 2020
@omnitube
Copy link

omnitube commented Sep 5, 2021

It would be great if we could point to a tsconfig file. I have a custom library with type definitions in my "paths" which I cannot use without pointing to my tsconfig.

@omnitube
Copy link

omnitube commented Sep 7, 2021

At minima, it would be great to be able to programmatically set our own compilerOptions dictionary. Otherwise, the only option available is to repeat @mahirk and create a custom fork of Spot, which is far from ideal. Any ideas?

@luukvhoudt
Copy link

Seems like the actually used tsconfig is hard coded, this is very unfortunate.

Shouldn't be to hard to implement a CLI flag to allow users to pass a tsconfig file. I will give it a try.

@KenEucker
Copy link

Checking in on this as I am just starting out with spot and have encountered this issue.

Is this ready for prime-time?

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

No branches or pull requests

6 participants