-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Change default of types to [] in tsconfig.json
#63031
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4a9fccf
2b70067
3040049
8eeb702
95e2cd0
25b06e8
148074c
83af771
5144841
3b0d338
e641e7e
89de5f6
387b02a
5b122ff
361221e
7f169c1
a2b2a62
73f106f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,13 +26,15 @@ import { | |
| emptyArray, | ||
| endsWith, | ||
| ensureTrailingDirectorySeparator, | ||
| equateValues, | ||
| every, | ||
| Extension, | ||
| extensionIsTS, | ||
| fileExtensionIs, | ||
| fileExtensionIsOneOf, | ||
| filter, | ||
| firstDefined, | ||
| flatten, | ||
| forEach, | ||
| forEachAncestorDirectory, | ||
| formatMessage, | ||
|
|
@@ -799,6 +801,14 @@ export function resolvePackageNameToPackageJson( | |
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Returns true if the types compiler option includes the "*" wildcard. | ||
| * @internal | ||
| */ | ||
| export function typesIncludesWildcard(types: readonly string[] | undefined): boolean { | ||
| return types?.includes("*") ?? false; | ||
| } | ||
|
|
||
| /** | ||
| * Given a set of options, returns the set of type directive names | ||
| * that should be included for this program automatically. | ||
|
|
@@ -808,13 +818,17 @@ export function resolvePackageNameToPackageJson( | |
| * this list is only the set of defaults that are implicitly included. | ||
| */ | ||
| export function getAutomaticTypeDirectiveNames(options: CompilerOptions, host: ModuleResolutionHost): string[] { | ||
| // Use explicit type list from tsconfig.json | ||
| if (options.types) { | ||
| // Default to [] if nothing specified | ||
| if (options.types === undefined) { | ||
| return emptyArray; | ||
| } | ||
|
|
||
| if (!typesIncludesWildcard(options.types)) { | ||
| // No wildcard, no need to iterate anything | ||
| return options.types; | ||
| } | ||
|
|
||
| // Walk the primary type lookup locations | ||
| const result: string[] = []; | ||
| const wildcardMatches: string[] = []; | ||
| if (host.directoryExists && host.getDirectories) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also need to fix
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 5b122ff. Updated FileIncludeKind.AutomaticTypeDirectiveFile handling in both programDiagnostics.ts and watch.ts to always use the "specified in compilerOptions" messages (removed implicit type library messages since types must now be explicit). |
||
| const typeRoots = getEffectiveTypeRoots(options, host); | ||
| if (typeRoots) { | ||
|
|
@@ -829,19 +843,19 @@ export function getAutomaticTypeDirectiveNames(options: CompilerOptions, host: M | |
| const isNotNeededPackage = host.fileExists(packageJsonPath) && (readJson(packageJsonPath, host) as PackageJson).typings === null; | ||
| if (!isNotNeededPackage) { | ||
| const baseFileName = getBaseFileName(normalized); | ||
|
|
||
| // At this stage, skip results with leading dot. | ||
| if (baseFileName.charCodeAt(0) !== CharacterCodes.dot) { | ||
| // Return just the type directive names | ||
| result.push(baseFileName); | ||
| wildcardMatches.push(baseFileName); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return result; | ||
|
|
||
RyanCavanaugh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Order potentially matters in program construction, so substitute | ||
| // in the wildcard in the position it was specified in the types array | ||
| return deduplicate(flatten(options.types.map(t => t === "*" ? wildcardMatches : t)), equateValues); | ||
| } | ||
|
|
||
| export interface TypeReferenceDirectiveResolutionCache extends PerDirectoryResolutionCache<ResolvedTypeReferenceDirectiveWithFailedLookupLocations>, NonRelativeNameResolutionCache<ResolvedTypeReferenceDirectiveWithFailedLookupLocations>, PackageJsonInfoCache { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,6 +52,7 @@ import { | |
| removeSuffix, | ||
| SourceFile, | ||
| TsConfigSourceFile, | ||
| typesIncludesWildcard, | ||
| } from "./_namespaces/ts.js"; | ||
|
|
||
| interface FileReasonToChainCache { | ||
|
|
@@ -400,7 +401,7 @@ export function createProgramDiagnostics(getCompilerOptionsObjectLiteralSyntax: | |
| ) : | ||
| undefined; | ||
| case FileIncludeKind.AutomaticTypeDirectiveFile: | ||
| if (!options.types) return undefined; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should check for a wildcard, no?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 7f169c1. Now returns early when wildcard is present using |
||
| if (typesIncludesWildcard(options.types)) return undefined; | ||
| configFileNode = getOptionsSyntaxByArrayElementValue(getCompilerOptionsObjectLiteralSyntax(), "types", reason.typeReference); | ||
| message = Diagnostics.File_is_entry_point_of_type_library_specified_here; | ||
| break; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ import { | |
| some, | ||
| toFileNameLowerCase, | ||
| TypeAcquisition, | ||
| typesIncludesWildcard, | ||
| Version, | ||
| versionMajorMinor, | ||
| } from "./_namespaces/ts.js"; | ||
|
|
@@ -133,7 +134,7 @@ export function discoverTypings( | |
| const exclude = typeAcquisition.exclude || []; | ||
|
|
||
| // Directories to search for package.json, bower.json and other typing information | ||
| if (!compilerOptions.types) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 7f169c1. Changed to use optional chaining: |
||
| if (typesIncludesWildcard(compilerOptions.types)) { | ||
| const possibleSearchDirs = new Set(fileNames.map(getDirectoryPath)); | ||
| possibleSearchDirs.add(projectRootPath); | ||
| possibleSearchDirs.forEach(searchDir => { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.