Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 30 additions & 15 deletions internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -13406,21 +13406,21 @@ func (c *Checker) getCannotFindNameDiagnosticForName(node *ast.Node) *diagnostic
case "document", "console":
return diagnostics.Cannot_find_name_0_Do_you_need_to_change_your_target_library_Try_changing_the_lib_compiler_option_to_include_dom
case "$":
return core.IfElse(c.compilerOptions.Types != nil,
diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slashjquery_and_then_add_jquery_to_the_types_field_in_your_tsconfig,
diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slashjquery)
case "describe", "suite", "it", "test":
return core.IfElse(c.compilerOptions.Types != nil,
diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_save_dev_types_Slashjest_or_npm_i_save_dev_types_Slashmocha_and_then_add_jest_or_mocha_to_the_types_field_in_your_tsconfig,
diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_save_dev_types_Slashjest_or_npm_i_save_dev_types_Slashmocha)
case "process", "require", "Buffer", "module":
return core.IfElse(c.compilerOptions.Types != nil,
diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashnode_and_then_add_node_to_the_types_field_in_your_tsconfig,
diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashnode)
return core.IfElse(c.compilerOptions.UsesWildcardTypes(),
diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slashjquery,
diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slashjquery_and_then_add_jquery_to_the_types_field_in_your_tsconfig)
case "beforeEach", "describe", "suite", "it", "test":
return core.IfElse(c.compilerOptions.UsesWildcardTypes(),
diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_save_dev_types_Slashjest_or_npm_i_save_dev_types_Slashmocha,
diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_save_dev_types_Slashjest_or_npm_i_save_dev_types_Slashmocha_and_then_add_jest_or_mocha_to_the_types_field_in_your_tsconfig)
case "process", "require", "Buffer", "module", "NodeJS":
return core.IfElse(c.compilerOptions.UsesWildcardTypes(),
diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashnode,
diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashnode_and_then_add_node_to_the_types_field_in_your_tsconfig)
case "Bun":
return core.IfElse(c.compilerOptions.Types != nil,
diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_Bun_Try_npm_i_save_dev_types_Slashbun_and_then_add_bun_to_the_types_field_in_your_tsconfig,
diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_Bun_Try_npm_i_save_dev_types_Slashbun)
return core.IfElse(c.compilerOptions.UsesWildcardTypes(),
diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_Bun_Try_npm_i_save_dev_types_Slashbun,
diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_Bun_Try_npm_i_save_dev_types_Slashbun_and_then_add_bun_to_the_types_field_in_your_tsconfig)
case "Map", "Set", "Promise", "ast.Symbol", "WeakMap", "WeakSet", "Iterator", "AsyncIterator", "SharedArrayBuffer", "Atomics", "AsyncIterable",
"AsyncIterableIterator", "AsyncGenerator", "AsyncGeneratorFunction", "BigInt", "Reflect", "BigInt64Array", "BigUint64Array":
return diagnostics.Cannot_find_name_0_Do_you_need_to_change_your_target_library_Try_changing_the_lib_compiler_option_to_1_or_later
Expand Down Expand Up @@ -14548,11 +14548,26 @@ func (c *Checker) markSymbolOfAliasDeclarationIfTypeOnly(aliasDeclaration *ast.N
}

func (c *Checker) resolveExternalModuleName(location *ast.Node, moduleReferenceExpression *ast.Node, ignoreErrors bool) *ast.Symbol {
errorMessage := diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations
errorMessage := c.getCannotResolveModuleNameErrorForSpecificModule(moduleReferenceExpression)
if errorMessage == nil {
errorMessage = diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations
}
ignoreErrors = ignoreErrors || c.compilerOptions.NoCheck.IsTrue()
return c.resolveExternalModuleNameWorker(location, moduleReferenceExpression, core.IfElse(ignoreErrors, nil, errorMessage), ignoreErrors, false /*isForAugmentation*/)
}

func (c *Checker) getCannotResolveModuleNameErrorForSpecificModule(moduleName *ast.Node) *diagnostics.Message {
if ast.IsStringLiteral(moduleName) {
if core.NodeCoreModules()[moduleName.Text()] {
if c.compilerOptions.UsesWildcardTypes() {
return diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashnode
}
return diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashnode_and_then_add_node_to_the_types_field_in_your_tsconfig
}
}
return nil
}

func (c *Checker) resolveExternalModuleNameWorker(location *ast.Node, moduleReferenceExpression *ast.Node, moduleNotFoundError *diagnostics.Message, ignoreErrors bool, isForAugmentation bool) *ast.Symbol {
if ast.IsStringLiteralLike(moduleReferenceExpression) {
return c.resolveExternalModule(location, moduleReferenceExpression.Text(), moduleNotFoundError, core.IfElse(!ignoreErrors, moduleReferenceExpression, nil), isForAugmentation)
Expand Down
4 changes: 2 additions & 2 deletions internal/compiler/fileInclude.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (r *FileIncludeReason) computeDiagnostic(program *Program, toFileName func(
}
case fileIncludeKindAutomaticTypeDirectiveFile:
data := r.asAutomaticTypeDirectiveFileData()
if program.Options().Types != nil {
if !program.Options().UsesWildcardTypes() {
if data.packageId.Name != "" {
return ast.NewCompilerDiagnostic(diagnostics.Entry_point_of_type_library_0_specified_in_compilerOptions_with_packageId_1, data.typeReference, data.packageId.String())
} else {
Expand Down Expand Up @@ -277,7 +277,7 @@ func (r *FileIncludeReason) toRelatedInfo(program *Program) *ast.Diagnostic {
}
}
case fileIncludeKindAutomaticTypeDirectiveFile:
if program.Options().Types != nil {
if !program.Options().UsesWildcardTypes() {
data := r.asAutomaticTypeDirectiveFileData()
if typesSyntax := tsoptions.GetOptionsSyntaxByArrayElementValue(program.includeProcessor.getCompilerOptionsObjectLiteralSyntax(program), "types", data.typeReference); typesSyntax != nil {
return tsoptions.CreateDiagnosticForNodeInSourceFile(config.ConfigFile.SourceFile, typesSyntax.AsNode(), diagnostics.File_is_entry_point_of_type_library_specified_here)
Expand Down
6 changes: 6 additions & 0 deletions internal/core/compileroptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package core

import (
"reflect"
"slices"
"strings"

"github.com/microsoft/typescript-go/internal/collections"
Expand Down Expand Up @@ -318,6 +319,11 @@ func (options *CompilerOptions) GetEffectiveTypeRoots(currentDirectory string) (
return typeRoots, false
}

// UsesWildcardTypes returns true if this option's types array includes "*"
func (options *CompilerOptions) UsesWildcardTypes() bool {
return slices.Contains(options.Types, "*")
}

func (options *CompilerOptions) GetIsolatedModules() bool {
return options.IsolatedModules == TSTrue || options.VerbatimModuleSyntax == TSTrue
}
Expand Down
3 changes: 0 additions & 3 deletions internal/fourslash/_scripts/failingTests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ TestAutoImportJsDocImport1
TestAutoImportModuleNone2
TestAutoImportNodeModuleSymlinkRenamed
TestAutoImportNodeNextJSRequire
TestAutoImportPackageJsonFilterExistingImport3
TestAutoImportPackageJsonImportsCaseSensitivity
TestAutoImportPackageRootPath
TestAutoImportPathsNodeModules
Expand Down Expand Up @@ -145,8 +144,6 @@ TestCompletionsImport_reExport_wrongName
TestCompletionsImport_require_addToExisting
TestCompletionsImport_typeOnly
TestCompletionsImport_umdDefaultNoCrash1
TestCompletionsImport_umdModules1_globalAccess
TestCompletionsImport_umdModules3_script
TestCompletionsImport_uriStyleNodeCoreModules2
TestCompletionsImport_uriStyleNodeCoreModules3
TestCompletionsImport_windowsPathsProjectRelative
Expand Down
25 changes: 20 additions & 5 deletions internal/module/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2026,11 +2026,15 @@ func ResolveConfig(moduleName string, containingFile string, host ResolutionHost
}

func GetAutomaticTypeDirectiveNames(options *core.CompilerOptions, host ResolutionHost) []string {
if options.Types != nil {
return options.Types
if !options.UsesWildcardTypes() {
if options.Types != nil {
return options.Types
}
return []string{}
}

var result []string
// Walk the primary type lookup locations
var wildcardMatches []string
typeRoots, _ := options.GetEffectiveTypeRoots(host.GetCurrentDirectory())
for _, root := range typeRoots {
if host.FS().DirectoryExists(root) {
Expand All @@ -2048,13 +2052,24 @@ func GetAutomaticTypeDirectiveNames(options *core.CompilerOptions, host Resoluti
if !isNotNeededPackage {
baseFileName := tspath.GetBaseFileName(normalized)
if !strings.HasPrefix(baseFileName, ".") {
result = append(result, baseFileName)
wildcardMatches = append(wildcardMatches, baseFileName)
}
}
}
}
}
return result

// Order potentially matters in program construction, so substitute
// in the wildcard in the position it was specified in the types array
var result []string
for _, t := range options.Types {
if t == "*" {
result = append(result, wildcardMatches...)
} else {
result = append(result, t)
}
}
return core.Deduplicate(result)
}

type ResolvedEntrypoints struct {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
anonymousModules.ts(1,1): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.
anonymousModules.ts(1,1): error TS2591: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node` and then add 'node' to the types field in your tsconfig.
anonymousModules.ts(1,8): error TS1437: Namespace must be given a name.
anonymousModules.ts(4,2): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.
anonymousModules.ts(4,2): error TS2591: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node` and then add 'node' to the types field in your tsconfig.
anonymousModules.ts(4,9): error TS1437: Namespace must be given a name.
anonymousModules.ts(10,2): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.
anonymousModules.ts(10,2): error TS2591: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node` and then add 'node' to the types field in your tsconfig.
anonymousModules.ts(10,9): error TS1437: Namespace must be given a name.


==== anonymousModules.ts (6 errors) ====
module {
~~~~~~
!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.
!!! error TS2591: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node` and then add 'node' to the types field in your tsconfig.
~
!!! error TS1437: Namespace must be given a name.
export var foo = 1;

module {
~~~~~~
!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.
!!! error TS2591: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node` and then add 'node' to the types field in your tsconfig.
~
!!! error TS1437: Namespace must be given a name.
export var bar = 1;
Expand All @@ -26,7 +26,7 @@ anonymousModules.ts(10,9): error TS1437: Namespace must be given a name.

module {
~~~~~~
!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.
!!! error TS2591: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node` and then add 'node' to the types field in your tsconfig.
~
!!! error TS1437: Namespace must be given a name.
var x = bar;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
constructorWithIncompleteTypeAnnotation.ts(11,13): error TS2503: Cannot find namespace 'module'.
constructorWithIncompleteTypeAnnotation.ts(11,13): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.
constructorWithIncompleteTypeAnnotation.ts(11,13): error TS2591: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node` and then add 'node' to the types field in your tsconfig.
constructorWithIncompleteTypeAnnotation.ts(11,19): error TS1005: ';' expected.
constructorWithIncompleteTypeAnnotation.ts(22,35): error TS1005: ')' expected.
constructorWithIncompleteTypeAnnotation.ts(22,39): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
Expand Down Expand Up @@ -108,7 +108,7 @@ constructorWithIncompleteTypeAnnotation.ts(261,1): error TS1128: Declaration or
~~~~~~
!!! error TS2503: Cannot find namespace 'module'.
~~~~~~
!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.
!!! error TS2591: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node` and then add 'node' to the types field in your tsconfig.
~
!!! error TS1005: ';' expected.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
@@= skipped -0, +0 lines =@@
-error TS-1: Pre-emit (93) and post-emit (94) diagnostic counts do not match! This can indicate that a semantic _error_ was added by the emit resolver - such an error may not be reflected on the command line or in the editor, but may be captured in a baseline here!
constructorWithIncompleteTypeAnnotation.ts(11,13): error TS2503: Cannot find namespace 'module'.
-constructorWithIncompleteTypeAnnotation.ts(11,13): error TS2591: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node` and then add 'node' to the types field in your tsconfig.
+constructorWithIncompleteTypeAnnotation.ts(11,13): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.
constructorWithIncompleteTypeAnnotation.ts(11,13): error TS2591: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node` and then add 'node' to the types field in your tsconfig.
constructorWithIncompleteTypeAnnotation.ts(11,19): error TS1005: ';' expected.
constructorWithIncompleteTypeAnnotation.ts(22,35): error TS1005: ')' expected.
constructorWithIncompleteTypeAnnotation.ts(22,39): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
@@= skipped -42, +41 lines =@@
constructorWithIncompleteTypeAnnotation.ts(159,30): error TS1005: '{' expected.
constructorWithIncompleteTypeAnnotation.ts(159,31): error TS2304: Cannot find name 'Property'.
Expand Down Expand Up @@ -36,16 +33,7 @@
==== constructorWithIncompleteTypeAnnotation.ts (93 errors) ====
declare module "fs" {
export class File {
@@= skipped -18, +15 lines =@@
~~~~~~
!!! error TS2503: Cannot find namespace 'module'.
~~~~~~
-!!! error TS2591: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node` and then add 'node' to the types field in your tsconfig.
+!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.
~
!!! error TS1005: ';' expected.

@@= skipped -120, +120 lines =@@
@@= skipped -138, +135 lines =@@
var undef = undefined;

var _\uD4A5\u7204\uC316\uE59F = local;
Expand Down
Loading