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

Salsa: Include declaration files in different directories #13213

Closed
saschanaz opened this issue Dec 29, 2016 · 8 comments
Closed

Salsa: Include declaration files in different directories #13213

saschanaz opened this issue Dec 29, 2016 · 8 comments
Labels
Needs More Info The issue still hasn't been fully clarified

Comments

@saschanaz
Copy link
Contributor

TypeScript Version:  nightly (2.2.0-dev.20161229)

Situation

I have an existing project written in pure JS. My file tree:

-declarations
  -node-foo.d.ts
  -node-bar.d.ts
-node_modules
  -foo/ (private)
  -bar/ (private)
  -baz/ (public)
  -@types/baz/ (public)
-sources
  -some.js
  -existing.js
  -source.js
  -in.js
  -pure.js
  -javascript.js

I want to add some node module declaration files for my private node modules. I added the modules on my package.json as git+ssh form to directly get them from git repositories. They are written in pure JS, so now I want to write some TS declaration for typing.

Expected behavior:

I should be able to include d.ts files from arbitrary directories as I can with TS project.

Actual behavior:

Salsa acquire types only from files within same directory ("sources" here).

@mhegazy
Copy link
Contributor

mhegazy commented Dec 29, 2016

Did you add path mapping? have you added them in the include in your jsconfig.json?

@mhegazy mhegazy added the Needs More Info The issue still hasn't been fully clarified label Dec 29, 2016
@saschanaz
Copy link
Contributor Author

saschanaz commented Dec 29, 2016

Yes, I added "declarations/node-foo.d.ts" or "declarations" or "declarations/*" but nothing worked.

I originally had no "include" or "files" and I think this should include every file.

{
    "compilerOptions": {
        "target": "es2015"
    },
    "typeAcquisition": {
        "enable": true
        // tried include here too
    }
    // tried include here
}

@mhegazy
Copy link
Contributor

mhegazy commented Dec 29, 2016

can you share a sample i can look at?

@saschanaz
Copy link
Contributor Author

Sorry for late response! I made a sample here: https://github.com/SaschaNaz/salsa-dts-sample/

Moving es-cancelable.d.ts into scripts folder suddenly activates typing, and returning it to declarations folder makes its type any.

@mhegazy
Copy link
Contributor

mhegazy commented Dec 30, 2016

thanks @saschanaz.

I am a bit confused about what you want to do in es-cancelable.d.ts. you have at the top import * as PG from "pg"; which makes this file a module, yet you do not export any thing. then you have a declare module "es-cancelable" { which is an "augmentation", to the same module!

i would say you should just stick with a modul, e.g.

/// declarations/es-cancelable.d.ts
import * as PG from "pg";

export class Foo {
    ...
}

and in your jsonfig.json add paths mapping:

{
    "compilerOptions": {
        "target": "es2015",
        "baseUrl": "./",
        "paths": {
            "*" :["declarations/*", "*" ]
        }
    },
    "typeAcquisition": {
        "enable": true
    }
}

then you should see:

animation

@saschanaz
Copy link
Contributor Author

saschanaz commented Dec 31, 2016

Great, now it works as expected! The es-cancelable.d.ts is newly written just to make a minimal repro. I hope TS language service show an error or a warning for this case rather than failing silently to resolve, should I open a new issue?

BTW, how can I turn on d.ts type checker with jsconfig.json? I tried adding a tsconfig.json to turn it on but it seems to be interfering with jsconfig.json.

@mhegazy
Copy link
Contributor

mhegazy commented Dec 31, 2016

errors are disabled if you are using a jsconfig.json. we should be enabling more of htese errors as part of #6802

@mhegazy
Copy link
Contributor

mhegazy commented Dec 31, 2016

the easiest way is to add a tsconfig.json on this folder, and open the files from this folder first. also running tsc in this folder would give you errors.

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Needs More Info The issue still hasn't been fully clarified
Projects
None yet
Development

No branches or pull requests

2 participants