microsoft / microsoft/TypeScript

`export as namespace` still allows access via properties in module files

Open
#36,313 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Domain: ES Modules
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

TypeScript Version: 3.8.0-dev.20200119

Search Terms: export as namespace

Code

someModule.d.ts:

export function foo (bar: string): void;
export as namespace someModule;

index.ts:

import { foo } from './someModule';

someModule.foo;
window.someModule.foo;
globalThis.someModule.foo;

Expected behavior:

All of the attempts to access someModule as a global namespace in index.ts should result in compile-time errors, as index.ts is not a script file.

Actual behavior:

window.someModule.foo and globalThis.someModule.foo do NOT result in compile-time errors.

Playground Link: N/A (requires multiple files)

Related Issues: None found

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 issue with the two files shown, someModule.d.ts and index.ts, using the reported TypeScript version or a current build. Compare diagnostics for direct, window, and globalThis access, then trace the compiler handling of export as namespace. Done means all three global-namespace accesses in the module file produce compile-time errors.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.