restjohn / typescript_custom_dts_issue

A small repository to demonstrate the issue that the TypeScript compiler does not emit custom type definitions (see https://github.com/microsoft/TypeScript/issues/35296).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Migrating Legacy JS Node Modules to TypeScript with Custom Type Definitions

This is a simple repository to demonstrate using TypeScript custom type definitions (.d.ts files) to help transition a JavaScript Node project to TypeScript.

Unfortunately, there is a TypeScript issue that prevents the TypeScript compiler from emitting custom type definitions from the input files to the output directory.

Build and Run

npm install
npm test

You will notice that npm test exits with an error because the script attempts to build the test TypeScript project, which references the src TypeScript project. The test project depends on the custom type definition in src, which the compiler does not emit to the src output directory, lib, so test fails to compile.

Build and Run with Custom Types

rm -rf lib test-lib
npm run test_with_types

The test_with_types script includes a step that copies the custom type definition files from src to lib. Now you will see that the the project builds correctly. However, this build requires an explicit compilation of src, then copying the .d.ts files, then compiling test, which defeats the purpose of project references with the -b flag for incremental builds.

About

A small repository to demonstrate the issue that the TypeScript compiler does not emit custom type definitions (see https://github.com/microsoft/TypeScript/issues/35296).


Languages

Language:TypeScript 68.7%Language:JavaScript 31.3%