Fix lib.includes('dom') check in containerSeemsToBeEmptyDomElement (#61481)

This commit is contained in:
Fróði Karlsson 2025-03-26 00:24:52 +01:00 committed by GitHub
parent 19b777260b
commit 29e6d6689d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 56 additions and 1 deletions

View File

@ -34454,7 +34454,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
function containerSeemsToBeEmptyDomElement(containingType: Type) {
return (compilerOptions.lib && !compilerOptions.lib.includes("dom")) &&
return (compilerOptions.lib && !compilerOptions.lib.includes("lib.dom.d.ts")) &&
everyContainedType(containingType, type => type.symbol && /^(?:EventTarget|Node|(?:HTML[a-zA-Z]*)?Element)$/.test(unescapeLeadingUnderscores(type.symbol.escapedName))) &&
isEmptyObjectType(containingType);
}

View File

@ -0,0 +1,10 @@
missingDomElement_UsingDomLib.ts(3,37): error TS2339: Property 'textContent' does not exist on type 'HTMLMissingElement'.
==== missingDomElement_UsingDomLib.ts (1 errors) ====
interface HTMLMissingElement {}
(({}) as any as HTMLMissingElement).textContent;
~~~~~~~~~~~
!!! error TS2339: Property 'textContent' does not exist on type 'HTMLMissingElement'.

View File

@ -0,0 +1,10 @@
//// [tests/cases/compiler/missingDomElement_UsingDomLib.ts] ////
//// [missingDomElement_UsingDomLib.ts]
interface HTMLMissingElement {}
(({}) as any as HTMLMissingElement).textContent;
//// [missingDomElement_UsingDomLib.js]
({}).textContent;

View File

@ -0,0 +1,9 @@
//// [tests/cases/compiler/missingDomElement_UsingDomLib.ts] ////
=== missingDomElement_UsingDomLib.ts ===
interface HTMLMissingElement {}
>HTMLMissingElement : Symbol(HTMLMissingElement, Decl(missingDomElement_UsingDomLib.ts, 0, 0))
(({}) as any as HTMLMissingElement).textContent;
>HTMLMissingElement : Symbol(HTMLMissingElement, Decl(missingDomElement_UsingDomLib.ts, 0, 0))

View File

@ -0,0 +1,21 @@
//// [tests/cases/compiler/missingDomElement_UsingDomLib.ts] ////
=== missingDomElement_UsingDomLib.ts ===
interface HTMLMissingElement {}
(({}) as any as HTMLMissingElement).textContent;
>(({}) as any as HTMLMissingElement).textContent : any
> : ^^^
>(({}) as any as HTMLMissingElement) : HTMLMissingElement
> : ^^^^^^^^^^^^^^^^^^
>({}) as any as HTMLMissingElement : HTMLMissingElement
> : ^^^^^^^^^^^^^^^^^^
>({}) as any : any
> : ^^^
>({}) : {}
> : ^^
>{} : {}
> : ^^
>textContent : any
> : ^^^

View File

@ -0,0 +1,5 @@
// @lib: es5,dom
interface HTMLMissingElement {}
(({}) as any as HTMLMissingElement).textContent;