mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 02:33:53 -06:00
Skip isBlockScopedNameDeclaredBeforeUse error in interface or type declarations
Fixes #35947.
This commit is contained in:
parent
dcc6c9461e
commit
e4babd40e0
@ -1418,7 +1418,7 @@ namespace ts {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!!(usage.flags & NodeFlags.JSDoc) || isInTypeQuery(usage)) {
|
||||
if (!!(usage.flags & NodeFlags.JSDoc) || isInTypeQuery(usage) || usageInTypeDeclaration()) {
|
||||
return true;
|
||||
}
|
||||
if (isUsedInFunctionOrInstanceProperty(usage, declaration)) {
|
||||
@ -1432,6 +1432,10 @@ namespace ts {
|
||||
}
|
||||
return false;
|
||||
|
||||
function usageInTypeDeclaration() {
|
||||
return !!findAncestor(usage, node => isInterfaceDeclaration(node) || isTypeAliasDeclaration(node));
|
||||
}
|
||||
|
||||
function isImmediatelyUsedInInitializerOfBlockScopedVariable(declaration: VariableDeclaration, usage: Node): boolean {
|
||||
switch (declaration.parent.parent.kind) {
|
||||
case SyntaxKind.VariableStatement:
|
||||
|
||||
18
tests/baselines/reference/forwardRefInTypeDeclaration.js
Normal file
18
tests/baselines/reference/forwardRefInTypeDeclaration.js
Normal file
@ -0,0 +1,18 @@
|
||||
//// [forwardRefInTypeDeclaration.ts]
|
||||
// forward ref ignored in a typeof
|
||||
declare let s: typeof s1;
|
||||
const s1 = "x";
|
||||
|
||||
// ignored anywhere in an interface (#35947)
|
||||
interface Foo2 { [s2]: number; }
|
||||
const s2 = "x";
|
||||
|
||||
// or in a type definition
|
||||
type Foo3 = { [s3]: number; }
|
||||
const s3 = "x";
|
||||
|
||||
|
||||
//// [forwardRefInTypeDeclaration.js]
|
||||
var s1 = "x";
|
||||
var s2 = "x";
|
||||
var s3 = "x";
|
||||
@ -0,0 +1,27 @@
|
||||
=== tests/cases/compiler/forwardRefInTypeDeclaration.ts ===
|
||||
// forward ref ignored in a typeof
|
||||
declare let s: typeof s1;
|
||||
>s : Symbol(s, Decl(forwardRefInTypeDeclaration.ts, 1, 11))
|
||||
>s1 : Symbol(s1, Decl(forwardRefInTypeDeclaration.ts, 2, 5))
|
||||
|
||||
const s1 = "x";
|
||||
>s1 : Symbol(s1, Decl(forwardRefInTypeDeclaration.ts, 2, 5))
|
||||
|
||||
// ignored anywhere in an interface (#35947)
|
||||
interface Foo2 { [s2]: number; }
|
||||
>Foo2 : Symbol(Foo2, Decl(forwardRefInTypeDeclaration.ts, 2, 15))
|
||||
>[s2] : Symbol(Foo2[s2], Decl(forwardRefInTypeDeclaration.ts, 5, 16))
|
||||
>s2 : Symbol(s2, Decl(forwardRefInTypeDeclaration.ts, 6, 5))
|
||||
|
||||
const s2 = "x";
|
||||
>s2 : Symbol(s2, Decl(forwardRefInTypeDeclaration.ts, 6, 5))
|
||||
|
||||
// or in a type definition
|
||||
type Foo3 = { [s3]: number; }
|
||||
>Foo3 : Symbol(Foo3, Decl(forwardRefInTypeDeclaration.ts, 6, 15))
|
||||
>[s3] : Symbol([s3], Decl(forwardRefInTypeDeclaration.ts, 9, 13))
|
||||
>s3 : Symbol(s3, Decl(forwardRefInTypeDeclaration.ts, 10, 5))
|
||||
|
||||
const s3 = "x";
|
||||
>s3 : Symbol(s3, Decl(forwardRefInTypeDeclaration.ts, 10, 5))
|
||||
|
||||
29
tests/baselines/reference/forwardRefInTypeDeclaration.types
Normal file
29
tests/baselines/reference/forwardRefInTypeDeclaration.types
Normal file
@ -0,0 +1,29 @@
|
||||
=== tests/cases/compiler/forwardRefInTypeDeclaration.ts ===
|
||||
// forward ref ignored in a typeof
|
||||
declare let s: typeof s1;
|
||||
>s : "x"
|
||||
>s1 : "x"
|
||||
|
||||
const s1 = "x";
|
||||
>s1 : "x"
|
||||
>"x" : "x"
|
||||
|
||||
// ignored anywhere in an interface (#35947)
|
||||
interface Foo2 { [s2]: number; }
|
||||
>[s2] : number
|
||||
>s2 : "x"
|
||||
|
||||
const s2 = "x";
|
||||
>s2 : "x"
|
||||
>"x" : "x"
|
||||
|
||||
// or in a type definition
|
||||
type Foo3 = { [s3]: number; }
|
||||
>Foo3 : Foo3
|
||||
>[s3] : number
|
||||
>s3 : "x"
|
||||
|
||||
const s3 = "x";
|
||||
>s3 : "x"
|
||||
>"x" : "x"
|
||||
|
||||
11
tests/cases/compiler/forwardRefInTypeDeclaration.ts
Normal file
11
tests/cases/compiler/forwardRefInTypeDeclaration.ts
Normal file
@ -0,0 +1,11 @@
|
||||
// forward ref ignored in a typeof
|
||||
declare let s: typeof s1;
|
||||
const s1 = "x";
|
||||
|
||||
// ignored anywhere in an interface (#35947)
|
||||
interface Foo2 { [s2]: number; }
|
||||
const s2 = "x";
|
||||
|
||||
// or in a type definition
|
||||
type Foo3 = { [s3]: number; }
|
||||
const s3 = "x";
|
||||
Loading…
x
Reference in New Issue
Block a user