Typescript import type declaration file In order to declaration Generate . They exist for one purpose only: to describe the shape of an existing module and they only contain type information used for type checking. ts files), you can avoid misusing libraries and get […] Oct 2, 2012 · Get Started With --allowJs If --allowJs gave you decent results and you want to write a better definition file yourself, you can combine --allowJs with --declaration to see TypeScript's "best guess" at the types of the library. ts files from JavaScript using JSDoc syntax. TypeScript 3. ts files as blueprints. Create a folder with the name typescript-type-defs or whatever name you want and then let's create a file called users-list. For example, including /// <reference types="node" /> in a declaration file declares that this file uses names declared in @types/node/index. VSCode does not recognize the declarations when I edit a file in a project that includes this library. g Apr 16, 2023 · Make sure your TypeScript compiler is generating the correct type definition files and that the "types" option in your package. 7, TypeScript added support for generating . e. Compilers other than TypeScript may also use this information when deciding whether to emit a value, but may not do the same checks that TypeScript does to check if exports are a type or a value. Think of . Nov 2, 2023 · React Tips and Tricks — importing types in Typescript If you are like me, you may have only learned one way to import when you started with React. ts” file in TypeScript? . json specifies "main": "main. d. , whether the file is a module or a script) by the presence of any import or export declarations. 8 Release NotesIn conjunction with import type, TypeScript 3. The only way I could make this work was us Feb 17, 2024 · Create the Index Declaration File: In the index. @types/lib-name). 8 also adds a new compiler flag to control what happens with imports that won’t be utilized at runtime: importsNotUsedAsValues. import type counts as an import declaration, so if it were the only import/export statement in the file, substituting a type Here, our package depends on the browserify and typescript packages. /pages/FriendCard' Your FriendCard file is exporting a variable and that variable is referencing the anonymous function. ts module, you can use the import type statement: import type {alphanumeric} from '. global scope, declaration files, module augmentation, and typing non-JavaScript files. By reading this guide, you’ll have the tools to write complex declaration Dec 14, 2016 · A while back we talked about how TypeScript 2. Before we set sail into the mighty river of TypeScript, it’s pivotal to understand the role of type declaration files. *~ For example, if you were writing a file for "super-greeter", this Feb 2, 2024 · This tutorial teach the reader when to use the import type and the import feature of TypeScript. Declared in a JSDoc @typedef tag. ts: Oct 31, 2024 · Type declaration files have a . ts extension and contain declarations that help Typescript understand the types within a library. In this blog post, we will explore the fundamental concepts, usage methods, common practices, and best practices of importing types from `. May 19, 2017 · Now, considering I import with import promisify = require('es6-promisify'), how do I tell TypeScript that the promisify import is annotated in vendor. A global “Hello, world” library Mar 30, 2021 · Push your TypeScript library to next level by applying industry standards to your declaration files. Declaration Files Learning TypeScript 's Declaration Files chapter describes how to use declaration files and value declarations to inform TypeScript about modules and values not declared in your source code: Creating declaration files with . ts file to hold a custom namespace with general-purpose types for my application. ts File? A . Jun 18, 2020 · A Type Declaration or Type Definition file is a TypeScript file but with . TypeScript includes declaration files for all of the standardized built-in APIs available in JavaScript runtimes. Each type of major library Jun 13, 2017 · It helps to work around problems like defining types to library A which is designed to fit the same API as library B. Creating Declaration Files (. This flag takes 3 different values: remove: this is today’s behavior of dropping these imports. Mar 16, 2021 · A declaration file is a file that does not contain any executable code but contains descriptions of code that exists outside of the project files. My project has a file global. ts) Declaration files use the . Because there are dependencies Apr 6, 2024 · How I fixed some trouble importing types in . ts files, tools like TypeScript can provide intellisense and accurate types for un-typed code. Then, declare the global variable: Sep 25, 2020 · I have a working solution to - export types defined from declaration file, that can be used within my project and to be exported out to external projects. add the code suggested in the accepted answer to that file: Jan 17, 2025 · Type Declaration Files (. This guide covers how to identify common library patterns, and how to write declaration files which correspond to that pattern. ts files are type definition files which describe the external API of your module. Declared in a TypeScript declaration, either global or imported. This approach is nice if you have a proper module, but if you want to share types between modules though, better use import . Its primary purpose is to provide type definitions for JavaScript code. They exist for one purpose only: to describe the shape of an existing module and May 17, 2021 · } Remember to add the corresponding dependencies, for example: yarn add -D @jest/types # Jest yarn add -D @types/eslint # ESLint yarn add -D @types/tailwindcss # Tailwind < 3. The type can be: Primitive, like string or number. ts; and thus, this package needs to be included in the compilation along with the declaration file. when I ctrl+clicked the isURL import, it opened up the right type definition, defined in the @types/validator package), but it still didn't recognize the import as a function. Needless Namespacing If you’re converting a program from namespaces to modules, it can be easy to end up with a file that looks like this: May 16, 2017 · Note that TypeScript tries really, really hard to resolve and include type declaration files automatically for the developer, but libraries like color-js which don't specify a types location in their package. Jul 23, 2025 · Specific Type Import: Import individual types using curly braces around the names, separated by commas. Jun 14, 2023 · If your declaration file represents a module and you want to export types, use the export keyword to make them accessible for import in other TypeScript files that use the module. By default, TypeScript can’t infer types, so you need to define these files to help the type checker, but also to get better autocompletion in your code editor. Dec 4, 2024 · If verbatimModuleSyntax is turned off, TypeScript does some checks to see whether an import is a type or a value by checking the source file exports. json, it will be included by default. Jul 7, 2022 · What is a . In this blog post, we will explore how to properly import type declaration files in Typescript. It'd look something like this ⤵︎ Mar 23, 2017 · Therefore, use export {} to make the declaration file a module, import types with import type, and then use declare global to define globally accessible types. Dec 13, 2020 · Simply speaking, typescript declaration files are used to allow typescript to understand JS. Create and export a type/interface in a file (e. css or . ts files I had some trouble making something work in my Astro site. Module syntax The TypeScript compiler recognizes standard ECMAScript module syntax in TypeScript and JavaScript files and many forms of CommonJS syntax in JavaScript files. ts files are called type declaration files. Jul 14, 2017 · This file is a module, but it adds a declaration of MyApp. It’s going to continue to be the default, and is a non-breaking change. Types @type You can reference types with the “@type” tag. This comprehensive guide covers methods like using declaration files, importing libraries with type definitions, and handling JavaScript without type definitions. ts) file containing `declare module 'isomath';` TS7016 This means that the module does not include TypeScript Oct 11, 2017 · So for example, assuming the typings cli has downloaded a type declaration in the location /project/path/to/types, then at the very top of a typescript file that needs the declaration, the following piece of code needs to be added: Jul 10, 2024 · Type-scraping will help prevent potential errors very early in the development lifecycle, allowing more quality code. Features that require the TypeScript compiler to output actual code are not supported. Modern TypeScript code is built on the ES Module system - every . I recommend you give the official typescript handbook a read through to fully understand the concept, particularly the “do’s and dont’s” section. Namespace-creating declarations create a namespace, which contains names that are accessed using a dotted notation. This consolidates them into a single entry point for importing Usage in JavaScript Files: In your JavaScript files, you can now import all declarations from index. This is a stripped version of my index. ts file in TypeScript. org Oct 19, 2025 · These files allow you to declare types for JavaScript libraries or code without having an implementation. ts file? A type declaration file in Typescript? TLDR . First, TypeScript files have two kinds of scopes global scope If your file hasn't any import or export line, this file would be executed in global scope that all declaration in it are visible outside this file. ts files Jul 1, 2023 · Did you manually rename the generated . These files help TypeScript understand the structure of existing JavaScript libraries or codebases, enabling better type checking and autocompletion in your editor. The Declaration Files section is designed to teach you how to write a high-quality TypeScript Declaration File. May 11, 2021 · In TypeScript they are called Type Declaration files. /some-file' to resolve to an ES module that can be loaded at runtime, and that I expect it'll be exporting a value named SomeClass for me to use. Jan 31, 2024 · These files are essential for the TypeScript compiler, serving as a bridge between your strongly-typed syntax and the wild west of JavaScript’s dynamic types. ts files for every TypeScript or JavaScript file inside your project. ts, but you can also reference it or for a library specify its location in the package. ts IDEs know how to deal with these and since they are . js files. from Apr 27, 2025 · A . The package. ts, they are automatically "imported" into each file. ts? Currently, tsc keeps returning Could not find a declaration file for module 'es6-promisify'. Try `npm i --save-dev @types/some-library` if it exists or add a new declaration (. Jan 10, 2025 · This helps TypeScript distinguish between type exports and actual value exports, which is particularly useful when using TypeScript’s declaration merging features. MyThing in other TypeScript code without importing it. ts files to . We need to assume basic familiarity with the TypeScript language in order to get started. This includes things like methods and properties of built-in types like string or function, top-level names like Math and Object, and their associated types. This guide is structured by showing documentation for some API, along with sample usage of that API, and explaining how to write the corresponding declaration. Jan 8, 2024 · Introduction TypeScript enhances JavaScript by adding types to the language. How TypeScript models JavaScript modulesThis document is divided into four sections: The first section develops the theory behind how TypeScript approaches modules. Feb 26, 2024 · Understanding declare module in TypeScript TypeScript, an extension of JavaScript, introduces a type system that can significantly enhance code quality and developer productivity, especially in … Dec 4, 2019 · I have 2 typescript projects, 1 depends on the other. As the error says, you can't import a . Multi-file namespaces Here, we’ll split our Validation namespace across many files. Mar 22, 2017 · I didn't find a declaration file for 'google-spreadsheet' so I'm trying to create one by myself: in typings -> modules, I've added a new folder named "google-spreadsheet", and there I've added a new file named "index. . scripts: Explore local vs. ts file, import and re-export all declarations from the individual Child1Props. 175 globalThis is the future. for e. ts` files in TypeScript. 1 This technique is also useful in projects that are in the middle of a TypeScript migration, i. The purpose of this guide is to teach you how to write a high-quality definition file. I thought it would be interesting to look at Dec 28, 2023 · I'm creating a type declaration file for an existing vanilla JavaScript library (npm package). I tried as you suggested to create a main. , when you mix JavaScript and TypeScript files. If you want to be able to write the correct module-related compiler options for any situation, reason about how to integrate TypeScript with other tools, or understand how TypeScript processes dependency packages, this is the place 35 This mean you should type this module. Nov 15, 2023 · In the final chapter of our 10-part TypeScript Deep Dive series, we explore an essential aspect of TypeScript development — DefinitelyTyped and Declaration Files/Modules. Creating . I've tried importing my custom files in a regular javascript file, and everything works as expected; I can see the loader I created running, and I get the expected output. Importing Other Assets To use non-code assets with TypeScript, we need to defer the type for these imports. UMD library documentation is hard to distinguish from global library documentation. The built-in TypeScript compiler is able to do so because it includes a type checker that knows which imports are of types and/or values. They describe the shape of a JavaScript module (or Jun 29, 2018 · You first need to create a new TypeScript declaration file with the file extension . ts file without any imports or exports being present in the same file. ts and put it in my src directory. To import the alphanumeric type from the Types. Dec 23, 2016 · For example, if you're trying to import a file, such as a . ts declaration file? Background I'm writing a cf. g. ts' or this file doesn't exist so you get the second error. I was stuck until I found an excellent resource on Stack Overflow. ES Modules allow us to better tree shake and generate smaller files. Declaration files, if you’re not familiar, are just files that describe the shape of an existing JavaScript codebase to TypeScript. The type definitions for the Google Maps JavaScript API contain no modules, only a namespace. They describe the shape and behavior of existing JavaScript code Aug 24, 2018 · I've written about TypeScript imports on my blog before, but as I recently learned, I haven't covered all the cases. We still want to import them into TypeScript files, but we also do not want to generate definition files. I strongly suggest to familiarising with typescript's documentation on declaration files. ts) can streamline your development process. ts instead of types/index. In this same typings directory, I have some other files declaring constants but they never import anything and work as expected. Oct 17, 2021 · You shouldn't need to import your type declarations at all to manually annotate each js variable with its type. This tutorial will guide May 21, 2025 · Photo by Masaaki Komori / Unsplash When writing TypeScript code, it’s common to import types from other files to structure and annotate your code more effectively. We utilize, however, lots of libraries as amd Modules, which we do not want to convert to TypeScript. Mar 1, 2022 · In a React TypeScript project, there are 2 ways we can use Types and Interfaces. If you want to use your types using this import, you have to write them in a simple . ts file like that: src/@types/app. This includes: using enums using private, protected or public modifiers in constructor functions together with I can't find many guide/best practice for this, so is it a good practice to: import types I need individually into each file where I use them, OR declare all types with d. Sep 7, 2016 · declare - without any import or export keywords - defines declaration files automatically picked by TypeScript, which is an useful feature to add typing to legacy modules (npm installed packages without TypeScript definitions). ts extension and contain type information without implementations: Apr 12, 2021 · We look into how to write TypeScript declaration files to use JavasScript React components in TypeScript. There are also a few TypeScript-specific syntax extensions that can be used in TypeScript files and/or JSDoc comments. Mar 11, 2025 · Learn how to import JavaScript in TypeScript with ease. May 10, 2022 · But the problem is sometimes I would just need to import a . ts file and declare the globals, but still it does not work. These . ts Files from . json nor use a typings or @types convention, the compiler just isn't able to find it. May 17, 2016 · If you have module. Jun 17, 2023 · TypeScript was picking out the right reference in the . Sometimes, importing types from external libraries into a global declaration file (. Let's find out what is that practically. browserify does not bundle its declaration files with its npm packages, so we needed to depend on @types/browserify for its declarations. This means that when I'm in this file, it properly finds it. Consuming From there you’ll be able to use lodash in your TypeScript code with no fuss. Easiest way would be to put your declaration file at lib/Movable. However, there's a subtle but powerful distinction between a regular import and an import type statement that many developers overlook. js' implicitly has an 'any' type. Now that the questions can be more aligned with how declarations are used we can paraphrase the questions to answer them in a way that is more Declaration File Theory: A Deep Dive Structuring modules to give the exact API shape you want can be tricky. May 22, 2023 · A d. ts. ts Jul 7, 2023 · TypeScript doesn't support this pattern: https://github. json file to point to the directory containing your generated type definition files. For example, once you’ve npm install -ed your type declarations, you can use imports and write Mar 27, 2021 · The TypeScript compiler determines whether a TypeScript file’s top level scope is module-scoped or globally scoped (i. For my project I named it custom. module. 0, when an import path ends in an extension that isn’t a known JavaScript or TypeScript file extension, the compiler will look for a declaration file for that path in the form of {file basename}. Feb 27, 2024 · The error "Could not find declaration file for module" occurs when TypeScript cannot find the type declaration for a module. Jan 6, 2025 · A . Mar 2, 2017 · @花生PeA depends on your setup, if you don't have files: or include lines in your tsconfig. These are useful when using Node modules that do not contain any TypeScript interfaces, types, or declaration files. ts file, or declaration file, is a TypeScript file that provides type information for JavaScript code. webp file, you can place a * at the beginning of the file type declaration. Our package exposes declarations from each of those, so any user of our Jan 8, 2025 · When working on a TypeScript project, you might encounter the error: Could not find a declaration file for module 'some-library'. Unfortunately, I can't find a way to import these . Jul 2, 2021 · Cannot use import statement outside a module I'm not getting any warnings while typing, but when uploading the changes and updating the npm package in my actual application. That is, all features that just disappear when transpiling to JavaScript, such as type annotations or interface declarations. js". ts files. May 19, 2017 · The documentation has a good resource on declaration files and some templates for various kinds of declaration files. Consider importing 'User' instead of '@types/User'. Is there anything I can do (make local. ts Declaring types and values with the declare keyword Changing global types using global values, global interface merges, and global augmentations In TypeScript 5. If I write import {SomeClass} from '. So what so special about these Type Declaration files and how they are different from normal TypeScript files with . Michael Jackson, TypeScript Advocate When working on a TypeScript project, you Splitting Across Files As our application grows, we’ll want to split the code across multiple files to make it easier to maintain. the mysql2 package is designed to fit mostly the same API as the mysql package, so you can cover the majority of usage by just defining this typescript def file: How JavaScript Modules are Defined In TypeScript, just as in ECMAScript 2015, any file containing a top-level import or export is considered a module. The most common case for learning how . import from 'app' mean implicitly import from 'app. Now the type of the array propagates into the ArrayMetadata type. How do I add types for the final build, either inferred from components automatically or manually with definition files? Feb 15, 2017 · So, the way it works in TypeScript is as follows: If you want an interface/type that you can simply use without having to import it in the consuming module said interface must reside in a . I used Astro locals and I had to type a variable I shared using locals. ts filename extension. Declaration files bridge this gap, allowing TypeScript to type-check your code when you use external JavaScript libraries. I can import my types with both import and import type statements. Understanding how to Oct 22, 2023 · What Are Declaration Files? Declaration files are files with a . See full list on typescriptlang. This works for both modules and global code. The types which are exported can then be re-used by consumers of the modules using either import or import type in TypeScript code or JSDoc imports. Therefore, they can't be imported using the standard import directive. Both seem to work The resulting declaration file can then be used to describe the exported virtual TypeScript types of a JavaScript library or module when a third-party developer consumes it from TypeScript. In your case, you can just define a file with 'ts' only on can be exported and imported easily without going into type definition complexities. ts" which has the following content: It is worth noting that if the npm package already includes its declaration file as described in Publishing, downloading the corresponding @types package is not needed. 0 made it easier to grab declaration files for your favorite library. MyThing to the global scope, so you can still use MyApp. Jul 7, 2022 · What is a “. ts there with code: Jan 6, 2025 · What is a . In your case you most likely want to keep your types and interfaces in a a separate ts/tsx file. css' The old approach will no longer compile. So we would create global variables like this: Using VSCode, I can hover over t in this file and it tells me that it has the proper type as defined in my original index. If you do have files or include, then just add the path to local declaration file. Jul 26, 2023 · The "include" option is for including the files in your whole project not just type declaration generation. ts filename extensions? you are telling typescript to import the FriendCard class from the file '. {extension}. But when I build the library, there are no types included. ts file is only useful in a TypeScript project, which allows TypeScript to do type-inference on a JavaScript module. Enhance your TypeScript projects by effectively integrating existing JavaScript code. ts file is a TypeScript declaration file. txt file without importing anything from the "text package", which is why I was wondering if there is some sort of way, as you install a package to install a global type that does not require to import anything else for the type to apply. This is how the node. ts and module. Mar 26, 2025 · Why Do We Need Declaration Files? When you use JavaScript libraries in a TypeScript project, the TypeScript compiler needs to understand what functions, classes, and types these libraries provide. Aug 27, 2021 · Question How do I import types from a library in a . ts file is an ES module which can import and be imported by other ES modules. By using declaration files (also called . ts file (i. Before writing a global declaration file, make sure the library isn’t actually UMD. Even though the files are separate, they can each contribute to the same namespace and can be consumed as if they were all defined in one place. Apr 23, 2022 · I created the project with the vue-ts preset and in my component I have defined props with their types, and used some interfaces. They describe the shape of a JavaScript module (or object) without actually Nov 17, 2023 · Cannot import type declaration files. ts files, so they are available throughout the app without needing to import? Thank you! It is the solution, but not exactly what I want. For example, we might want a module that can be invoked with or without new to produce different types, has a variety of named types exposed in a hierarchy, and has some properties on the module object as well. There are many ways of offering a library for consumption in JavaScript, and you’ll need to write your declaration file to match it. ts file that several of the TypeScript samples use is consumed. ts extension that contain type information for TypeScript. Not the other way around. preserve: this export interface MyInterface { // } export const enum MyEnum { // } export type MyType = { // } I have read about the new feature import type for the latest typescript here. ts files in your codebase. Conversely, a file without any top-level import or export declarations is treated as a script whose contents are available in the global scope (and therefore to modules as well). From now on you’ll need to import CSS modules as: import { box } from '. ts as a single entry point. ts file, so your declarations won't be considered. These files contain type definitions, interfaces, and other type-related information that TypeScript can use to validate your code. Aug 8, 2020 · Maybe you are using some library that doesn't have its types (i. ts lol) that will make my complex types available everywhere except move them to global? Feb 7, 2022 · You will follow different code samples in your own TypeScript environment, showing how to use the import and export keyword, how to set default exports, and how to make files with overwritten exports objects compatible with your code. json file. json. If you still want to use type definition define 'typeRoots' in tsconfig. js file in your JS project. cts after the build? Feb 24, 2023 · Declaration files are used to type existing javascript files. com/microsoft/TypeScri Become a TypeScript Wizard with my free beginners TypeScript Course:more Sep 7, 2023 · Diagnose and solve common TypeScript module problems, such as having multiple fallback locations and the irregular location of dependencies. You can also adjust the "typeRoots" option in your tsconfig. If you want to resolve the warning, then import the shared. Another solution to explore is to add a typescript declaration file @types/myTypes. As far as I understand, it is meant to fix specific problems which seem mostly to happen when importing from . A . You can use most JSDoc type syntax and any TypeScript syntax, from the most basic like string to the most advanced, like conditional May 2, 2021 · The web moves forward and so do we. This set up means you can own the editor experience of TypeScript-powered editors without porting your project to TypeScript, or having to maintain . Identifying a Global Library from Code Global library code is usually extremely simple. In TypeScript, a declaration creates entities in at least one of three groups: namespace, type, or value. ts) file containing `declare module 'some-library';` Feb 24, 2023 · Import statements that only import types are generally removed when the TypeScript compiler transpiles TypeScript syntax to JavaScript syntax. If it's an external public module you might just be able to install its types with a npm install @types/name_of_the_module (Some modules even have their definition files inside the lib now. Creating Type Definitions for Third-Party Libraries When using JavaScript libraries without TypeScript definitions, you can create your own type definitions using declare. Mar 24, 2017 · I have noImplicitAny set to true for my TypeScript compiler. ts) describe the types of variables, functions, classes, and modules in JavaScript code, enabling TypeScript to understand and provide type safety for untyped libraries or custom code. Rename the d. Today, most popular globally-accessible libraries are actually written as UMD libraries (see below). For more information see the TypeScript changelog blog. js files With TypeScript 3. After changing the imports, it compiles correctly and looks as expected. ts or ideally a . The reference tag here allows us to locate the declaration file that contains the declaration for the ambient module. /Types'; Code language: TypeScript (typescript) npm install --save-dev @types/lodash If the npm package already includes its declaration typings in the package bundle, downloading the corresponding @types package is not needed. comp files in my typescript files. I also Doing so allows you to use TypeScript’s type-only features. With . Typescript is not happy with this module implicitly not having any definition file. Mastering this feature can lead to cleaner, more efficient, and safer TypeScript codebases Modules, Scripts, and Declaration Files Understand TypeScript modules vs. so if you exclude other files (set it to only the files you need declarations for), those files won't be seen by typescript at all and you will get lots of errors. FileA) and import it and use it in another file (FileB). ts) are used to describe the shape of a JavaScript module. ts with some utility types and this types just available everywhere. tsx) files I cannot import svg file with this statement: 68 I want to switch from JavaScript to TypeScript to help with code management as our project gets larger. If you haven’t already, you should read the TypeScript Handbook to familiarize yourself with basic concepts, especially types and modules. Jul 23, 2021 · TS6137: Cannot import type declaration files when importing from @types Asked 4 years, 4 months ago Modified 3 years ago Viewed 3k times In TypeScript, declaration files (. /mystyles. How can we achieve that? e. All Types Import: Use * as ModuleName to import all exported types from a module. 'promisify. /some-file'; I'm making a statement that I expect '. ts in the same folder, the compiler will skip the module. Let's create a simple example with TypeScript code. typescript, on the other hand, packages its declaration files, so there was no need for any additional dependencies. Importing and exporting TypeScript-specific declarations Type aliases, interfaces, enums, and namespaces Jan 9, 2020 · Try `npm install @types/my-untyped-module` if it exists or add a new declaration (. i. If it finds a TypeScript input file, it knows a JavaScript file will exist after compilation, and if it finds a declaration file, it knows a compilation (perhaps someone else’s) already happened and created a JavaScript file at the same time as the declaration file. But if I import like below, the error goes away. json file is pointing to the correct location. When I use an import like the following, it throws an error because I am not explicitly defining a type for the foo variable: import * Jun 23, 2017 · In typescript(*. Aug 5, 2020 · After compilation, TypeScript removes the import statement of all declaration files since a type declaration import doesn’t contain a value that will be useful at the runtime. ts file or move it to another folder. ts file is simply a Typescript convention known as a declaration file. Mar 6, 2020 · It turns out that Typescript declaration files seem to be one of the complex things to grasp because of the lack of the documentation and vague explanations from community. Importing and exporting TypeScript-specific declarations Type aliases, interfaces, enums, and namespaces Broadly speaking, the way you structure your declaration file depends on how the library is consumed. An easy way to think of triple-slash-reference-types directives are as an import for declaration packages. I can generate the typescript declaration files by setting "declaration": true in tsconfig (which would be applicable to both projects).