TypeStrong / TypeStrong/ts-loader

Enum values from d.ts files cause exception when build with transpileOnly=true

Open
#331 23 comments 25 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help wanted pinned
Dominant language
TypeScript
Stars
3.5k
Forks
439
Avg merge
17h 17m
Merged PRs (30d)
2

Description

I tried to speed up build process. And transpileOnly=true works amazing!
Until I use any enum value in my code.

Example:
Definition file: definitions.d.ts

declare module MyModule {
  export const enum MyEnum {
    EnumValue1 = 0,
    EnumValue2 = 1
  }
}

TS file: example.ts

/// <reference path="./definitions.d.ts" />
console.log(MyModule.MyEnum.EnumValue1);

In runtime I get error: "MyModule is not defined"
Is there any way to force ts-loader NOT to ignore some specific *.d.ts files when I use transpileOnly=true? (something like transpileOnlyExcept...)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure from definitions.d.ts and example.ts with transpileOnly=true, then inspect how ts-loader handles referenced declaration files. Done means the example's enum access no longer fails at runtime with "MyModule is not defined", with the behavior covered by an appropriate loader test.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.