7

Background

I have created a component library using react (plain js). I am in the process of creating Typescript definitions for the components so that consumers of the component library can use the components in a type-safe manner in their Typescript applications.

Question

What is the recommended way, if there is one, to check that the definitions manually created are correct? I am trying to catch issues before consumers have to highlighting any problems.

Investigation so far...

I have looked at https://github.com/asgerf/tscheck but it doesn't always work.

I also looked at DefinitelyTyped contribution guide: https://github.com/DefinitelyTyped/DefinitelyTyped#create-a-new-package. This says to create a typescript file with sample code for type-checking only...is this just a matter of compiling the *.test.ts file with the typescript compiler?

3
  • TypeScript code (like any other code) will be "correct" once there are no compile errors - so is your question about how to write correct .d.ts files?
    – messerbill
    Mar 7, 2018 at 11:20
  • I recently came across this paper which discusses this topic. Maybe it's useful to you.
    – Tao
    Mar 7, 2018 at 11:25
  • 2
    In a way... more along the lines of " I have written a .d.ts file I believe to be correct. Is there a way to confirm that what I think is correct is in fact correct...From your answer it appears that I need to write some typescript that uses the definitions
    – Davie
    Mar 7, 2018 at 11:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.