microsoft / microsoft/TypeScript

Report error if code precedes /// reference

Open
#1,920 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Domain: Something Else Help Wanted
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

a.ts:

'use strict'
/// <reference path='b.d.ts'/>

var x: Foo;

b.d.ts:

interface Foo { x: string; }
declare module "b" {
        export = Foo;
}
D:\test\refs\a> tsc a.ts
a.ts(4,8): error TS2304: Cannot find name 'Foo'.

There's no mention in section 11.1.1 of the spec that /// references must be the first thing in a file in order to work, although I do remember us deciding that was the case at one point. If that is the rule we should update the spec appropriately. We should also add an error to the compiler or else you may spend awhile trying to figure this out since we don't provide much (read: anything) in the way of diagnostics for debugging reference resolution.

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 case with a.ts, b.d.ts, and tsc a.ts, then read specification section 11.1.1 and the compiler's reference-resolution diagnostics. Determine whether the documented rule requires references to come first and define done as updating the specification and/or reporting a clear compiler error for the ordering mistake.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.