spot icon indicating copy to clipboard operation
spot copied to clipboard

spot doesn't seem to read tsconfig

Open ccakes opened this issue 3 years ago • 7 comments

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

ccakes avatar Nov 06 '20 19:11 ccakes

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.

mahirk avatar Nov 12 '20 01:11 mahirk

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.

lfportal avatar Nov 19 '20 10:11 lfportal

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

ccakes avatar Nov 19 '20 10:11 ccakes

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 avatar Sep 05 '21 20:09 omnitube

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?

omnitube avatar Sep 07 '21 00:09 omnitube

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.

luukvhoudt avatar Sep 13 '21 10:09 luukvhoudt

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

Is this ready for prime-time?

KenEucker avatar Nov 20 '21 01:11 KenEucker