`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.

Assessment

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

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.

Description

Bug Domain: ES Modules

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

Dominant language
Go
Stars
111k
Forks
14.4k
Avg merge
1d 19h
Merged PRs (30d)
117

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.

More from microsoft/TypeScript

All issues in microsoft/TypeScript

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.