Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 13.7k
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
4a9fccf2b7006730400498eeb70295e2cd025b06e8148074c83af77151448413b0d338e641e7e89de5f6387b02a5b122ff361221e7f169c1a2b2a6273f106fFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
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 ContributorAuthor 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.
Uh oh!There was an error while loading. Please reload this page. | ||
| // 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? ContributorAuthor 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 ContributorAuthor 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.
Uh oh!
There was an error while loading. Please reload this page.