Skip to content

Commit eebe33a

Browse files
fix: use typeRoot instead of candidate when resolving types references from config (microsoft#2614)
1 parent 62596ef commit eebe33a

13 files changed

Lines changed: 26 additions & 76 deletions

internal/module/resolver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ func (r *resolutionState) resolveTypeReferenceDirective(typeRoots []string, from
337337
}
338338
for _, typeRoot := range typeRoots {
339339
candidate := r.getCandidateFromTypeRoot(typeRoot)
340-
directoryExists := r.resolver.host.FS().DirectoryExists(candidate)
340+
directoryExists := r.resolver.host.FS().DirectoryExists(typeRoot)
341341
if !directoryExists && r.tracer != nil {
342342
r.tracer.write(diagnostics.Directory_0_does_not_exist_skipping_all_lookups_in_it, typeRoot)
343343
}

testdata/baselines/reference/submodule/compiler/typeReferenceDirectiveScopedPackageCustomTypeRoot.trace.json

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,34 @@ Resolving real path for '/types/@scoped/typescache/index.d.ts', result '/types/@
77
======== Type reference directive '@scoped/typescache' was successfully resolved to '/types/@scoped/typescache/index.d.ts', primary: true. ========
88
======== Resolving type reference directive '@scoped/nodemodulescache', containing file '/__inferred type names__.ts', root directory '/types,/node_modules,/node_modules/@types'. ========
99
Resolving with primary search path '/types, /node_modules, /node_modules/@types'.
10-
Directory '/types' does not exist, skipping all lookups in it.
10+
File '/types/@scoped/nodemodulescache.d.ts' does not exist.
1111
File '/node_modules/@scoped/nodemodulescache.d.ts' does not exist.
1212
File '/node_modules/@scoped/nodemodulescache/package.json' does not exist.
1313
File '/node_modules/@scoped/nodemodulescache/index.d.ts' exists - use it as a name resolution result.
1414
Resolving real path for '/node_modules/@scoped/nodemodulescache/index.d.ts', result '/node_modules/@scoped/nodemodulescache/index.d.ts'.
1515
======== Type reference directive '@scoped/nodemodulescache' was successfully resolved to '/node_modules/@scoped/nodemodulescache/index.d.ts', primary: true. ========
1616
======== Resolving type reference directive '@scoped/attypescache', containing file '/__inferred type names__.ts', root directory '/types,/node_modules,/node_modules/@types'. ========
1717
Resolving with primary search path '/types, /node_modules, /node_modules/@types'.
18-
Directory '/types' does not exist, skipping all lookups in it.
19-
Directory '/node_modules' does not exist, skipping all lookups in it.
18+
File '/types/@scoped/attypescache.d.ts' does not exist.
19+
File '/node_modules/@scoped/attypescache.d.ts' does not exist.
2020
Scoped package detected, looking in 'scoped__attypescache'
21-
Directory '/node_modules/@types' does not exist, skipping all lookups in it.
21+
File '/node_modules/@types/scoped__attypescache.d.ts' does not exist.
2222
Resolving type reference directive for program that specifies custom typeRoots, skipping lookup in 'node_modules' folder.
2323
======== Type reference directive '@scoped/attypescache' was not resolved. ========
2424
======== Resolving type reference directive '@mangled/typescache', containing file '/__inferred type names__.ts', root directory '/types,/node_modules,/node_modules/@types'. ========
2525
Resolving with primary search path '/types, /node_modules, /node_modules/@types'.
26-
Directory '/types' does not exist, skipping all lookups in it.
27-
Directory '/node_modules' does not exist, skipping all lookups in it.
2826
Scoped package detected, looking in 'mangled__typescache'
29-
Directory '/node_modules/@types' does not exist, skipping all lookups in it.
27+
File '/node_modules/@types/mangled__typescache.d.ts' does not exist.
3028
Resolving type reference directive for program that specifies custom typeRoots, skipping lookup in 'node_modules' folder.
3129
======== Type reference directive '@mangled/typescache' was not resolved. ========
3230
======== Resolving type reference directive '@mangled/nodemodulescache', containing file '/__inferred type names__.ts', root directory '/types,/node_modules,/node_modules/@types'. ========
3331
Resolving with primary search path '/types, /node_modules, /node_modules/@types'.
34-
Directory '/types' does not exist, skipping all lookups in it.
35-
Directory '/node_modules' does not exist, skipping all lookups in it.
3632
Scoped package detected, looking in 'mangled__nodemodulescache'
37-
Directory '/node_modules/@types' does not exist, skipping all lookups in it.
33+
File '/node_modules/@types/mangled__nodemodulescache.d.ts' does not exist.
3834
Resolving type reference directive for program that specifies custom typeRoots, skipping lookup in 'node_modules' folder.
3935
======== Type reference directive '@mangled/nodemodulescache' was not resolved. ========
4036
======== Resolving type reference directive '@mangled/attypescache', containing file '/__inferred type names__.ts', root directory '/types,/node_modules,/node_modules/@types'. ========
4137
Resolving with primary search path '/types, /node_modules, /node_modules/@types'.
42-
Directory '/types' does not exist, skipping all lookups in it.
43-
Directory '/node_modules' does not exist, skipping all lookups in it.
4438
Scoped package detected, looking in 'mangled__attypescache'
4539
File '/node_modules/@types/mangled__attypescache.d.ts' does not exist.
4640
File '/node_modules/@types/mangled__attypescache/package.json' does not exist.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
======== Resolving type reference directive 'phaser', containing file '/__inferred type names__.ts', root directory '/typings'. ========
22
Resolving with primary search path '/typings'.
3-
Directory '/typings' does not exist, skipping all lookups in it.
3+
File '/typings/phaser.d.ts' does not exist.
44
Resolving type reference directive for program that specifies custom typeRoots, skipping lookup in 'node_modules' folder.
55
======== Type reference directive 'phaser' was not resolved. ========

testdata/baselines/reference/submodule/compiler/typeReferenceDirectiveWithTypeAsFile.errors.txt

Lines changed: 0 additions & 11 deletions
This file was deleted.

testdata/baselines/reference/submodule/compiler/typeReferenceDirectiveWithTypeAsFile.errors.txt.diff

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
//// [tests/cases/compiler/typeReferenceDirectiveWithTypeAsFile.ts] ////
22

33
=== /a.ts ===
4-
54
a;
5+
>a : Symbol(a, Decl(phaser.d.ts, 0, 13))
6+
7+
=== /node_modules/phaser/types/phaser.d.ts ===
8+
declare const a: number;
9+
>a : Symbol(a, Decl(phaser.d.ts, 0, 13))
610

testdata/baselines/reference/submodule/compiler/typeReferenceDirectiveWithTypeAsFile.symbols.diff

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
======== Resolving type reference directive 'phaser', containing file '/__inferred type names__.ts', root directory '/node_modules/phaser/types'. ========
22
Resolving with primary search path '/node_modules/phaser/types'.
3-
Directory '/node_modules/phaser/types' does not exist, skipping all lookups in it.
4-
Resolving type reference directive for program that specifies custom typeRoots, skipping lookup in 'node_modules' folder.
5-
======== Type reference directive 'phaser' was not resolved. ========
3+
File '/node_modules/phaser/types/phaser.d.ts' exists - use it as a name resolution result.
4+
File '/node_modules/phaser/package.json' does not exist.
5+
Resolving real path for '/node_modules/phaser/types/phaser.d.ts', result '/node_modules/phaser/types/phaser.d.ts'.
6+
======== Type reference directive 'phaser' was successfully resolved to '/node_modules/phaser/types/phaser.d.ts', primary: true. ========

testdata/baselines/reference/submodule/compiler/typeReferenceDirectiveWithTypeAsFile.types

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,9 @@
22

33
=== /a.ts ===
44
a;
5-
>a : any
5+
>a : number
6+
7+
=== /node_modules/phaser/types/phaser.d.ts ===
8+
declare const a: number;
9+
>a : number
610

testdata/baselines/reference/submodule/compiler/typeReferenceDirectiveWithTypeAsFile.types.diff

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)