Skip to content

Commit aff834f

Browse files
committed
Add test that shows types file does not act as ambient module declaration
1 parent 40bb75c commit aff834f

11 files changed

+156
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/a.ts(1,20): error TS2307: Cannot find module 'phaser' or its corresponding type declarations.
2+
3+
4+
==== /a.ts (1 errors) ====
5+
import { a2 } from "phaser";
6+
~~~~~~~~
7+
!!! error TS2307: Cannot find module 'phaser' or its corresponding type declarations.
8+
==== /typings/phaser/types/phaser.d.ts (0 errors) ====
9+
export const a2: number;
10+
11+
==== /typings/phaser/package.json (0 errors) ====
12+
{ "name": "phaser", "version": "1.2.3", "types": "types/phaser.d.ts" }
13+
14+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//// [tests/cases/compiler/moduleResolutionAsTypeReferenceDirective.ts] ////
2+
3+
//// [phaser.d.ts]
4+
export const a2: number;
5+
6+
//// [package.json]
7+
{ "name": "phaser", "version": "1.2.3", "types": "types/phaser.d.ts" }
8+
9+
10+
//// [a.ts]
11+
import { a2 } from "phaser";
12+
13+
//// [a.js]
14+
"use strict";
15+
exports.__esModule = true;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== /a.ts ===
2+
import { a2 } from "phaser";
3+
>a2 : Symbol(a2, Decl(a.ts, 0, 8))
4+
5+
=== /typings/phaser/types/phaser.d.ts ===
6+
export const a2: number;
7+
>a2 : Symbol(a2, Decl(phaser.d.ts, 0, 12))
8+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[
2+
"======== Resolving module 'phaser' from '/a.ts'. ========",
3+
"Module resolution kind is not specified, using 'NodeJs'.",
4+
"Loading module 'phaser' from 'node_modules' folder, target file types: TypeScript, Declaration.",
5+
"Directory '/node_modules' does not exist, skipping all lookups in it.",
6+
"Loading module 'phaser' from 'node_modules' folder, target file types: JavaScript.",
7+
"Directory '/node_modules' does not exist, skipping all lookups in it.",
8+
"======== Module name 'phaser' was not resolved. ========",
9+
"======== Resolving type reference directive 'phaser', containing file '/__inferred type names__.ts', root directory '/typings'. ========",
10+
"Resolving with primary search path '/typings'.",
11+
"File '/typings/phaser.d.ts' does not exist.",
12+
"Found 'package.json' at '/typings/phaser/package.json'.",
13+
"'package.json' does not have a 'typesVersions' field.",
14+
"'package.json' does not have a 'typings' field.",
15+
"'package.json' has 'types' field 'types/phaser.d.ts' that references '/typings/phaser/types/phaser.d.ts'.",
16+
"File '/typings/phaser/types/phaser.d.ts' exist - use it as a name resolution result.",
17+
"Resolving real path for '/typings/phaser/types/phaser.d.ts', result '/typings/phaser/types/phaser.d.ts'.",
18+
"======== Type reference directive 'phaser' was successfully resolved to '/typings/phaser/types/phaser.d.ts' with Package ID 'phaser/types/[email protected]', primary: true. ========"
19+
]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== /a.ts ===
2+
import { a2 } from "phaser";
3+
>a2 : any
4+
5+
=== /typings/phaser/types/phaser.d.ts ===
6+
export const a2: number;
7+
>a2 : number
8+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//// [tests/cases/compiler/moduleResolutionAsTypeReferenceDirectiveAmbient.ts] ////
2+
3+
//// [phaser.d.ts]
4+
declare module "phaser" {
5+
export const a2: number;
6+
}
7+
8+
//// [package.json]
9+
{ "name": "phaser", "version": "1.2.3", "types": "types/phaser.d.ts" }
10+
11+
12+
//// [a.ts]
13+
import { a2 } from "phaser";
14+
15+
//// [a.js]
16+
"use strict";
17+
exports.__esModule = true;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
=== /a.ts ===
2+
import { a2 } from "phaser";
3+
>a2 : Symbol(a2, Decl(a.ts, 0, 8))
4+
5+
=== /typings/phaser/types/phaser.d.ts ===
6+
declare module "phaser" {
7+
>"phaser" : Symbol("phaser", Decl(phaser.d.ts, 0, 0))
8+
9+
export const a2: number;
10+
>a2 : Symbol(a2, Decl(phaser.d.ts, 1, 16))
11+
}
12+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[
2+
"======== Resolving module 'phaser' from '/a.ts'. ========",
3+
"Module resolution kind is not specified, using 'NodeJs'.",
4+
"Loading module 'phaser' from 'node_modules' folder, target file types: TypeScript, Declaration.",
5+
"Directory '/node_modules' does not exist, skipping all lookups in it.",
6+
"Loading module 'phaser' from 'node_modules' folder, target file types: JavaScript.",
7+
"Directory '/node_modules' does not exist, skipping all lookups in it.",
8+
"======== Module name 'phaser' was not resolved. ========",
9+
"======== Resolving type reference directive 'phaser', containing file '/__inferred type names__.ts', root directory '/typings'. ========",
10+
"Resolving with primary search path '/typings'.",
11+
"File '/typings/phaser.d.ts' does not exist.",
12+
"Found 'package.json' at '/typings/phaser/package.json'.",
13+
"'package.json' does not have a 'typesVersions' field.",
14+
"'package.json' does not have a 'typings' field.",
15+
"'package.json' has 'types' field 'types/phaser.d.ts' that references '/typings/phaser/types/phaser.d.ts'.",
16+
"File '/typings/phaser/types/phaser.d.ts' exist - use it as a name resolution result.",
17+
"Resolving real path for '/typings/phaser/types/phaser.d.ts', result '/typings/phaser/types/phaser.d.ts'.",
18+
"======== Type reference directive 'phaser' was successfully resolved to '/typings/phaser/types/phaser.d.ts' with Package ID 'phaser/types/[email protected]', primary: true. ========"
19+
]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
=== /a.ts ===
2+
import { a2 } from "phaser";
3+
>a2 : number
4+
5+
=== /typings/phaser/types/phaser.d.ts ===
6+
declare module "phaser" {
7+
>"phaser" : typeof import("phaser")
8+
9+
export const a2: number;
10+
>a2 : number
11+
}
12+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// @noImplicitReferences: true
2+
// @typeRoots: /typings
3+
// @types: phaser
4+
// @traceResolution: true
5+
// @currentDirectory: /
6+
7+
// @Filename: /typings/phaser/types/phaser.d.ts
8+
export const a2: number;
9+
10+
// @Filename: /typings/phaser/package.json
11+
{ "name": "phaser", "version": "1.2.3", "types": "types/phaser.d.ts" }
12+
13+
14+
// @Filename: /a.ts
15+
import { a2 } from "phaser";

0 commit comments

Comments
 (0)