Definitelytyped: Question! How do I test my types with the library in question first

Created on 22 Aug 2020  路  6Comments  路  Source: DefinitelyTyped/DefinitelyTyped

So I modified an existing type definition and I want to test it and I am having a hard time finding the best method to test. I want to create a new project and import my changes but I don't know how to create the npm sub-package for my specific directory, and including definitely typed directly as a repository is not recognizing my type definitions at all, and I cannot seem to force tsconfig to import and prefer the necessary types.

I am a little confused, can someone help?

Most helpful comment

I was really excited about your solution, I wonder if I did something wrong.
image

I was unsuccessful, I still don't know how to associate the index.d.ts to the library in question.

@peterpeterblazejewicz

All 6 comments

@jcapinc
Create a project locally with all your settings and that 3rd party library, install types as usually.
For your own types, just create @types directory on project root (same folder where tscofnig is located) and just add the same structore that later will be used by DT types (folder with files), e.g. @types/json-minify, etc. That will be picked by default TSC resolving step.

...
tsconfig.json
...
/@types/json-minify
/@types/json-minify/index.d.ts
/@types/json-minify/json-minify-tests.ts
/@types/json-minify/tsconfig.json
/@types/json-minify/tsling.json

and then

import minify = require('json-minify');
...

once done with tests, you will get ready to copy DT definition including tests with real life usage.

I would have never thought of that! that looks excellent, I will go try that out and see if I can make that work.

I was really excited about your solution, I wonder if I did something wrong.
image

I was unsuccessful, I still don't know how to associate the index.d.ts to the library in question.

@peterpeterblazejewicz

sorry, I've was tricked by my actual setups. Nearly there,
so basically, the TSC looks for @types directories recursevily up, which means one could place a folder node_moules/@types directory up, with sample DT package and it will be looked up from a nested project, so, this would certainly work:
image
Open VSCode from argparse-test directory, install NPM packages as usually. The node will lookup current package.json, but the tsc will lookup up for @types:
https://www.typescriptlang.org/tsconfig#typeRoots

Thank you for this, I will give this a shot and report back to this thread how I fair.

image

This worked! Thank you so much! I will use this to finish my work on argparse and work on other types in the future - thank you so much!

Was this page helpful?
0 / 5 - 0 ratings