fix: correct name length criterion for spelling fixes (#49575)

Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
This commit is contained in:
AlCalzone
2022-07-07 09:08:37 -07:00
committed by GitHub
co-authored by Jake Bailey
parent 59238dbf90
commit f6684be95e
32 changed files with 245 additions and 95 deletions
+36 -20
View File
@@ -1874,7 +1874,7 @@ m2: ${(this.mapper2 as unknown as DebugTypeMapper).__debugToString().split("\n")
let result: Symbol | undefined;
let lastLocation: Node | undefined;
let lastSelfReferenceLocation: Node | undefined;
let propertyWithInvalidInitializer: Node | undefined;
let propertyWithInvalidInitializer: PropertyDeclaration | undefined;
let associatedDeclarationForContainingInitializerOrBindingName: ParameterDeclaration | BindingElement | undefined;
let withinDeferredContext = false;
const errorLocation = location;
@@ -2008,6 +2008,7 @@ m2: ${(this.mapper2 as unknown as DebugTypeMapper).__debugToString().split("\n")
if (ctor && ctor.locals) {
if (lookup(ctor.locals, name, meaning & SymbolFlags.Value)) {
// Remember the property node, it will be used later to report appropriate error
Debug.assertNode(location, isPropertyDeclaration);
propertyWithInvalidInitializer = location;
}
}
@@ -2204,11 +2205,31 @@ m2: ${(this.mapper2 as unknown as DebugTypeMapper).__debugToString().split("\n")
}
}
}
// The invalid initializer error is needed in two situation:
// 1. When result is undefined, after checking for a missing "this."
// 2. When result is defined
function checkAndReportErrorForInvalidInitializer() {
if (propertyWithInvalidInitializer && !(getEmitScriptTarget(compilerOptions) === ScriptTarget.ESNext && useDefineForClassFields)) {
// We have a match, but the reference occurred within a property initializer and the identifier also binds
// to a local variable in the constructor where the code will be emitted. Note that this is actually allowed
// with ESNext+useDefineForClassFields because the scope semantics are different.
error(errorLocation,
errorLocation && propertyWithInvalidInitializer.type && textRangeContainsPositionInclusive(propertyWithInvalidInitializer.type, errorLocation.pos)
? Diagnostics.Type_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor
: Diagnostics.Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor,
declarationNameToString(propertyWithInvalidInitializer.name), diagnosticName(nameArg!));
return true;
}
return false;
}
if (!result) {
if (nameNotFoundMessage) {
addLazyDiagnostic(() => {
if (!errorLocation ||
!checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg!) && // TODO: GH#18217
!checkAndReportErrorForInvalidInitializer() &&
!checkAndReportErrorForExtendingInterface(errorLocation) &&
!checkAndReportErrorForUsingTypeAsNamespace(errorLocation, name, meaning) &&
!checkAndReportErrorForExportingPrimitiveType(errorLocation, name) &&
@@ -2216,7 +2237,16 @@ m2: ${(this.mapper2 as unknown as DebugTypeMapper).__debugToString().split("\n")
!checkAndReportErrorForUsingNamespaceModuleAsValue(errorLocation, name, meaning) &&
!checkAndReportErrorForUsingValueAsType(errorLocation, name, meaning)) {
let suggestion: Symbol | undefined;
if (getSpellingSuggestions && suggestionCount < maximumSuggestionCount) {
let suggestedLib: string | undefined;
// Report missing lib first
if (nameArg) {
suggestedLib = getSuggestedLibForNonExistentName(nameArg);
if (suggestedLib) {
error(errorLocation, nameNotFoundMessage, diagnosticName(nameArg), suggestedLib);
}
}
// then spelling suggestions
if (!suggestedLib && getSpellingSuggestions && suggestionCount < maximumSuggestionCount) {
suggestion = getSuggestedSymbolForNonexistentSymbol(originalLocation, name, meaning);
const isGlobalScopeAugmentationDeclaration = suggestion?.valueDeclaration && isAmbientModule(suggestion.valueDeclaration) && isGlobalScopeAugmentation(suggestion.valueDeclaration);
if (isGlobalScopeAugmentationDeclaration) {
@@ -2238,16 +2268,9 @@ m2: ${(this.mapper2 as unknown as DebugTypeMapper).__debugToString().split("\n")
}
}
}
if (!suggestion) {
if (nameArg) {
const lib = getSuggestedLibForNonExistentName(nameArg);
if (lib) {
error(errorLocation, nameNotFoundMessage, diagnosticName(nameArg), lib);
}
else {
error(errorLocation, nameNotFoundMessage, diagnosticName(nameArg));
}
}
// And then fall back to unspecified "not found"
if (!suggestion && !suggestedLib && nameArg) {
error(errorLocation, nameNotFoundMessage, diagnosticName(nameArg));
}
suggestionCount++;
}
@@ -2255,14 +2278,7 @@ m2: ${(this.mapper2 as unknown as DebugTypeMapper).__debugToString().split("\n")
}
return undefined;
}
if (propertyWithInvalidInitializer && !(getEmitScriptTarget(compilerOptions) === ScriptTarget.ESNext && useDefineForClassFields)) {
// We have a match, but the reference occurred within a property initializer and the identifier also binds
// to a local variable in the constructor where the code will be emitted. Note that this is actually allowed
// with ESNext+useDefineForClassFields because the scope semantics are different.
const propertyName = (propertyWithInvalidInitializer as PropertyDeclaration).name;
error(errorLocation, Diagnostics.Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor,
declarationNameToString(propertyName), diagnosticName(nameArg!));
else if (checkAndReportErrorForInvalidInitializer()) {
return undefined;
}
+1 -1
View File
@@ -2105,7 +2105,7 @@ namespace ts {
* and 1 insertion/deletion at 3 characters)
*/
export function getSpellingSuggestion<T>(name: string, candidates: T[], getName: (candidate: T) => string | undefined): T | undefined {
const maximumLengthDifference = Math.min(2, Math.floor(name.length * 0.34));
const maximumLengthDifference = Math.max(2, Math.floor(name.length * 0.34));
let bestDistance = Math.floor(name.length * 0.4) + 1; // If the best result is worse than this, don't bother.
let bestCandidate: T | undefined;
for (const candidate of candidates) {
+4
View File
@@ -3507,6 +3507,10 @@
"category": "Error",
"code": 2843
},
"Type of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor.": {
"category": "Error",
"code": 2844
},
"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",
@@ -1,6 +1,6 @@
tests/cases/compiler/DateTimeFormatAndNumberFormatES2021.ts(1,29): error TS2339: Property 'formatRange' does not exist on type 'NumberFormat'.
tests/cases/compiler/DateTimeFormatAndNumberFormatES2021.ts(4,25): error TS2339: Property 'formatRange' does not exist on type 'NumberFormat'.
tests/cases/compiler/DateTimeFormatAndNumberFormatES2021.ts(5,25): error TS2339: Property 'formatRangeToParts' does not exist on type 'NumberFormat'.
tests/cases/compiler/DateTimeFormatAndNumberFormatES2021.ts(5,25): error TS2551: Property 'formatRangeToParts' does not exist on type 'NumberFormat'. Did you mean 'formatToParts'?
==== tests/cases/compiler/DateTimeFormatAndNumberFormatES2021.ts (3 errors) ====
@@ -14,6 +14,7 @@ tests/cases/compiler/DateTimeFormatAndNumberFormatES2021.ts(5,25): error TS2339:
!!! error TS2339: Property 'formatRange' does not exist on type 'NumberFormat'.
new Intl.NumberFormat().formatRangeToParts
~~~~~~~~~~~~~~~~~~
!!! error TS2339: Property 'formatRangeToParts' does not exist on type 'NumberFormat'.
!!! error TS2551: Property 'formatRangeToParts' does not exist on type 'NumberFormat'. Did you mean 'formatToParts'?
!!! related TS2728 /.ts/lib.es2018.intl.d.ts:71:9: 'formatToParts' is declared here.
new Intl.DateTimeFormat().formatRange
new Intl.DateTimeFormat().formatRangeToParts
@@ -1,4 +1,4 @@
tests/cases/conformance/async/es2017/asyncArrowFunction/asyncArrowFunction10_es2017.ts(3,11): error TS2304: Cannot find name 'await'.
tests/cases/conformance/async/es2017/asyncArrowFunction/asyncArrowFunction10_es2017.ts(3,11): error TS2552: Cannot find name 'await'. Did you mean 'Awaited'?
==== tests/cases/conformance/async/es2017/asyncArrowFunction/asyncArrowFunction10_es2017.ts (1 errors) ====
@@ -6,6 +6,6 @@ tests/cases/conformance/async/es2017/asyncArrowFunction/asyncArrowFunction10_es2
// Legal to use 'await' in a type context.
var v: await;
~~~~~
!!! error TS2304: Cannot find name 'await'.
!!! error TS2552: Cannot find name 'await'. Did you mean 'Awaited'?
}
@@ -1,4 +1,4 @@
tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction10_es5.ts(3,11): error TS2304: Cannot find name 'await'.
tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction10_es5.ts(3,11): error TS2552: Cannot find name 'await'. Did you mean 'Awaited'?
==== tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction10_es5.ts (1 errors) ====
@@ -6,6 +6,6 @@ tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction10_es5.ts
// Legal to use 'await' in a type context.
var v: await;
~~~~~
!!! error TS2304: Cannot find name 'await'.
!!! error TS2552: Cannot find name 'await'. Did you mean 'Awaited'?
}
@@ -1,4 +1,4 @@
tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction10_es6.ts(3,11): error TS2304: Cannot find name 'await'.
tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction10_es6.ts(3,11): error TS2552: Cannot find name 'await'. Did you mean 'Awaited'?
==== tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction10_es6.ts (1 errors) ====
@@ -6,6 +6,6 @@ tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction10_es6.ts
// Legal to use 'await' in a type context.
var v: await;
~~~~~
!!! error TS2304: Cannot find name 'await'.
!!! error TS2552: Cannot find name 'await'. Did you mean 'Awaited'?
}
@@ -1,4 +1,4 @@
tests/cases/conformance/async/es2017/functionDeclarations/asyncFunctionDeclaration13_es2017.ts(3,11): error TS2304: Cannot find name 'await'.
tests/cases/conformance/async/es2017/functionDeclarations/asyncFunctionDeclaration13_es2017.ts(3,11): error TS2552: Cannot find name 'await'. Did you mean 'Awaited'?
==== tests/cases/conformance/async/es2017/functionDeclarations/asyncFunctionDeclaration13_es2017.ts (1 errors) ====
@@ -6,6 +6,6 @@ tests/cases/conformance/async/es2017/functionDeclarations/asyncFunctionDeclarati
// Legal to use 'await' in a type context.
var v: await;
~~~~~
!!! error TS2304: Cannot find name 'await'.
!!! error TS2552: Cannot find name 'await'. Did you mean 'Awaited'?
}
@@ -1,4 +1,4 @@
tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration13_es5.ts(3,11): error TS2304: Cannot find name 'await'.
tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration13_es5.ts(3,11): error TS2552: Cannot find name 'await'. Did you mean 'Awaited'?
==== tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration13_es5.ts (1 errors) ====
@@ -6,6 +6,6 @@ tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration1
// Legal to use 'await' in a type context.
var v: await;
~~~~~
!!! error TS2304: Cannot find name 'await'.
!!! error TS2552: Cannot find name 'await'. Did you mean 'Awaited'?
}
@@ -1,4 +1,4 @@
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration13_es6.ts(3,11): error TS2304: Cannot find name 'await'.
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration13_es6.ts(3,11): error TS2552: Cannot find name 'await'. Did you mean 'Awaited'?
==== tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration13_es6.ts (1 errors) ====
@@ -6,6 +6,6 @@ tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration1
// Legal to use 'await' in a type context.
var v: await;
~~~~~
!!! error TS2304: Cannot find name 'await'.
!!! error TS2552: Cannot find name 'await'. Did you mean 'Awaited'?
}
@@ -11,13 +11,13 @@ tests/cases/compiler/bigintWithoutLib.ts(13,38): error TS2554: Expected 0 argume
tests/cases/compiler/bigintWithoutLib.ts(14,38): error TS2554: Expected 0 arguments, but got 2.
tests/cases/compiler/bigintWithoutLib.ts(15,38): error TS2554: Expected 0 arguments, but got 2.
tests/cases/compiler/bigintWithoutLib.ts(18,18): error TS2583: Cannot find name 'BigInt64Array'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2020' or later.
tests/cases/compiler/bigintWithoutLib.ts(18,38): error TS2552: Cannot find name 'BigInt64Array'. Did you mean 'bigIntArray'?
tests/cases/compiler/bigintWithoutLib.ts(19,19): error TS2552: Cannot find name 'BigInt64Array'. Did you mean 'bigIntArray'?
tests/cases/compiler/bigintWithoutLib.ts(20,19): error TS2552: Cannot find name 'BigInt64Array'. Did you mean 'bigIntArray'?
tests/cases/compiler/bigintWithoutLib.ts(18,38): error TS2583: Cannot find name 'BigInt64Array'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2020' or later.
tests/cases/compiler/bigintWithoutLib.ts(19,19): error TS2583: Cannot find name 'BigInt64Array'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2020' or later.
tests/cases/compiler/bigintWithoutLib.ts(20,19): error TS2583: Cannot find name 'BigInt64Array'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2020' or later.
tests/cases/compiler/bigintWithoutLib.ts(20,34): error TS2737: BigInt literals are not available when targeting lower than ES2020.
tests/cases/compiler/bigintWithoutLib.ts(20,38): error TS2737: BigInt literals are not available when targeting lower than ES2020.
tests/cases/compiler/bigintWithoutLib.ts(20,42): error TS2737: BigInt literals are not available when targeting lower than ES2020.
tests/cases/compiler/bigintWithoutLib.ts(21,19): error TS2552: Cannot find name 'BigInt64Array'. Did you mean 'bigIntArray'?
tests/cases/compiler/bigintWithoutLib.ts(21,19): error TS2583: Cannot find name 'BigInt64Array'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2020' or later.
tests/cases/compiler/bigintWithoutLib.ts(22,19): error TS2583: Cannot find name 'BigInt64Array'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2020' or later.
tests/cases/compiler/bigintWithoutLib.ts(23,19): error TS2583: Cannot find name 'BigInt64Array'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2020' or later.
tests/cases/compiler/bigintWithoutLib.ts(24,19): error TS2583: Cannot find name 'BigInt64Array'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2020' or later.
@@ -97,16 +97,13 @@ tests/cases/compiler/bigintWithoutLib.ts(56,36): error TS2345: Argument of type
~~~~~~~~~~~~~
!!! error TS2583: Cannot find name 'BigInt64Array'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2020' or later.
~~~~~~~~~~~~~
!!! error TS2552: Cannot find name 'BigInt64Array'. Did you mean 'bigIntArray'?
!!! related TS2728 tests/cases/compiler/bigintWithoutLib.ts:18:5: 'bigIntArray' is declared here.
!!! error TS2583: Cannot find name 'BigInt64Array'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2020' or later.
bigIntArray = new BigInt64Array(10);
~~~~~~~~~~~~~
!!! error TS2552: Cannot find name 'BigInt64Array'. Did you mean 'bigIntArray'?
!!! related TS2728 tests/cases/compiler/bigintWithoutLib.ts:18:5: 'bigIntArray' is declared here.
!!! error TS2583: Cannot find name 'BigInt64Array'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2020' or later.
bigIntArray = new BigInt64Array([1n, 2n, 3n]);
~~~~~~~~~~~~~
!!! error TS2552: Cannot find name 'BigInt64Array'. Did you mean 'bigIntArray'?
!!! related TS2728 tests/cases/compiler/bigintWithoutLib.ts:18:5: 'bigIntArray' is declared here.
!!! error TS2583: Cannot find name 'BigInt64Array'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2020' or later.
~~
!!! error TS2737: BigInt literals are not available when targeting lower than ES2020.
~~
@@ -115,8 +112,7 @@ tests/cases/compiler/bigintWithoutLib.ts(56,36): error TS2345: Argument of type
!!! error TS2737: BigInt literals are not available when targeting lower than ES2020.
bigIntArray = new BigInt64Array([1, 2, 3]);
~~~~~~~~~~~~~
!!! error TS2552: Cannot find name 'BigInt64Array'. Did you mean 'bigIntArray'?
!!! related TS2728 tests/cases/compiler/bigintWithoutLib.ts:18:5: 'bigIntArray' is declared here.
!!! error TS2583: Cannot find name 'BigInt64Array'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2020' or later.
bigIntArray = new BigInt64Array(new ArrayBuffer(80));
~~~~~~~~~~~~~
!!! error TS2583: Cannot find name 'BigInt64Array'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2020' or later.
@@ -1,4 +1,4 @@
tests/cases/compiler/weird.js(1,1): error TS2304: Cannot find name 'someFunction'.
tests/cases/compiler/weird.js(1,1): error TS2552: Cannot find name 'someFunction'. Did you mean 'Function'?
tests/cases/compiler/weird.js(1,23): error TS7006: Parameter 'BaseClass' implicitly has an 'any' type.
tests/cases/compiler/weird.js(9,17): error TS7006: Parameter 'error' implicitly has an 'any' type.
@@ -6,7 +6,8 @@ tests/cases/compiler/weird.js(9,17): error TS7006: Parameter 'error' implicitly
==== tests/cases/compiler/weird.js (3 errors) ====
someFunction(function(BaseClass) {
~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'someFunction'.
!!! error TS2552: Cannot find name 'someFunction'. Did you mean 'Function'?
!!! related TS2728 /.ts/lib.es5.d.ts:324:13: 'Function' is declared here.
~~~~~~~~~
!!! error TS7006: Parameter 'BaseClass' implicitly has an 'any' type.
'use strict';
@@ -39,7 +39,7 @@ tests/cases/compiler/commonMissingSemicolons.ts(26,18): error TS1003: Identifier
tests/cases/compiler/commonMissingSemicolons.ts(27,1): error TS2304: Cannot find name 'functionMyFunction'.
tests/cases/compiler/commonMissingSemicolons.ts(30,1): error TS1435: Unknown keyword or identifier. Did you mean 'interface'?
tests/cases/compiler/commonMissingSemicolons.ts(30,1): error TS2304: Cannot find name 'interfaced'.
tests/cases/compiler/commonMissingSemicolons.ts(30,12): error TS1434: Unexpected keyword or identifier.
tests/cases/compiler/commonMissingSemicolons.ts(30,12): error TS1435: Unknown keyword or identifier. Did you mean 'interface'?
tests/cases/compiler/commonMissingSemicolons.ts(30,12): error TS2304: Cannot find name 'myInterface2'.
tests/cases/compiler/commonMissingSemicolons.ts(32,1): error TS2693: 'interface' only refers to a type, but is being used as a value here.
tests/cases/compiler/commonMissingSemicolons.ts(32,11): error TS1438: Interface must be given a name.
@@ -193,7 +193,7 @@ tests/cases/compiler/commonMissingSemicolons.ts(78,1): error TS1128: Declaration
~~~~~~~~~~
!!! error TS2304: Cannot find name 'interfaced'.
~~~~~~~~~~~~
!!! error TS1434: Unexpected keyword or identifier.
!!! error TS1435: Unknown keyword or identifier. Did you mean 'interface'?
~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'myInterface2'.
interface interface { }
@@ -1,22 +1,22 @@
tests/cases/compiler/constructorParametersInVariableDeclarations.ts(2,17): error TS2304: Cannot find name 'x'.
tests/cases/compiler/constructorParametersInVariableDeclarations.ts(3,22): error TS2304: Cannot find name 'x'.
tests/cases/compiler/constructorParametersInVariableDeclarations.ts(4,23): error TS2304: Cannot find name 'x'.
tests/cases/compiler/constructorParametersInVariableDeclarations.ts(10,17): error TS2304: Cannot find name 'x'.
tests/cases/compiler/constructorParametersInVariableDeclarations.ts(11,22): error TS2304: Cannot find name 'x'.
tests/cases/compiler/constructorParametersInVariableDeclarations.ts(12,23): error TS2304: Cannot find name 'x'.
tests/cases/compiler/constructorParametersInVariableDeclarations.ts(2,17): error TS2301: Initializer of instance member variable 'a' cannot reference identifier 'x' declared in the constructor.
tests/cases/compiler/constructorParametersInVariableDeclarations.ts(3,22): error TS2301: Initializer of instance member variable 'b' cannot reference identifier 'x' declared in the constructor.
tests/cases/compiler/constructorParametersInVariableDeclarations.ts(4,23): error TS2301: Initializer of instance member variable 'c' cannot reference identifier 'x' declared in the constructor.
tests/cases/compiler/constructorParametersInVariableDeclarations.ts(10,17): error TS2301: Initializer of instance member variable 'a' cannot reference identifier 'x' declared in the constructor.
tests/cases/compiler/constructorParametersInVariableDeclarations.ts(11,22): error TS2301: Initializer of instance member variable 'b' cannot reference identifier 'x' declared in the constructor.
tests/cases/compiler/constructorParametersInVariableDeclarations.ts(12,23): error TS2301: Initializer of instance member variable 'c' cannot reference identifier 'x' declared in the constructor.
==== tests/cases/compiler/constructorParametersInVariableDeclarations.ts (6 errors) ====
class A {
private a = x;
~
!!! error TS2304: Cannot find name 'x'.
!!! error TS2301: Initializer of instance member variable 'a' cannot reference identifier 'x' declared in the constructor.
private b = { p: x };
~
!!! error TS2304: Cannot find name 'x'.
!!! error TS2301: Initializer of instance member variable 'b' cannot reference identifier 'x' declared in the constructor.
private c = () => x;
~
!!! error TS2304: Cannot find name 'x'.
!!! error TS2301: Initializer of instance member variable 'c' cannot reference identifier 'x' declared in the constructor.
constructor(x: number) {
}
}
@@ -24,13 +24,13 @@ tests/cases/compiler/constructorParametersInVariableDeclarations.ts(12,23): erro
class B {
private a = x;
~
!!! error TS2304: Cannot find name 'x'.
!!! error TS2301: Initializer of instance member variable 'a' cannot reference identifier 'x' declared in the constructor.
private b = { p: x };
~
!!! error TS2304: Cannot find name 'x'.
!!! error TS2301: Initializer of instance member variable 'b' cannot reference identifier 'x' declared in the constructor.
private c = () => x;
~
!!! error TS2304: Cannot find name 'x'.
!!! error TS2301: Initializer of instance member variable 'c' cannot reference identifier 'x' declared in the constructor.
constructor() {
var x = 1;
}
@@ -1,4 +1,4 @@
tests/cases/compiler/es6MemberScoping.ts(7,21): error TS2304: Cannot find name 'store'.
tests/cases/compiler/es6MemberScoping.ts(7,21): error TS2301: Initializer of instance member variable '_store' cannot reference identifier 'store' declared in the constructor.
==== tests/cases/compiler/es6MemberScoping.ts (1 errors) ====
@@ -10,7 +10,7 @@ tests/cases/compiler/es6MemberScoping.ts(7,21): error TS2304: Cannot find name '
}
public _store = store; // should be an error.
~~~~~
!!! error TS2304: Cannot find name 'store'.
!!! error TS2301: Initializer of instance member variable '_store' cannot reference identifier 'store' declared in the constructor.
}
class Foo2 {
@@ -1,7 +1,7 @@
tests/cases/conformance/classes/propertyMemberDeclarations/initializerReferencingConstructorParameters.ts(4,9): error TS2304: Cannot find name 'x'.
tests/cases/conformance/classes/propertyMemberDeclarations/initializerReferencingConstructorParameters.ts(5,15): error TS2304: Cannot find name 'x'.
tests/cases/conformance/classes/propertyMemberDeclarations/initializerReferencingConstructorParameters.ts(4,9): error TS2301: Initializer of instance member variable 'a' cannot reference identifier 'x' declared in the constructor.
tests/cases/conformance/classes/propertyMemberDeclarations/initializerReferencingConstructorParameters.ts(5,15): error TS2844: Type of instance member variable 'b' cannot reference identifier 'x' declared in the constructor.
tests/cases/conformance/classes/propertyMemberDeclarations/initializerReferencingConstructorParameters.ts(10,9): error TS2663: Cannot find name 'x'. Did you mean the instance member 'this.x'?
tests/cases/conformance/classes/propertyMemberDeclarations/initializerReferencingConstructorParameters.ts(11,15): error TS2304: Cannot find name 'x'.
tests/cases/conformance/classes/propertyMemberDeclarations/initializerReferencingConstructorParameters.ts(11,15): error TS2844: Type of instance member variable 'b' cannot reference identifier 'x' declared in the constructor.
tests/cases/conformance/classes/propertyMemberDeclarations/initializerReferencingConstructorParameters.ts(23,9): error TS2663: Cannot find name 'x'. Did you mean the instance member 'this.x'?
@@ -11,10 +11,10 @@ tests/cases/conformance/classes/propertyMemberDeclarations/initializerReferencin
class C {
a = x; // error
~
!!! error TS2304: Cannot find name 'x'.
!!! error TS2301: Initializer of instance member variable 'a' cannot reference identifier 'x' declared in the constructor.
b: typeof x; // error
~
!!! error TS2304: Cannot find name 'x'.
!!! error TS2844: Type of instance member variable 'b' cannot reference identifier 'x' declared in the constructor.
constructor(x) { }
}
@@ -24,7 +24,7 @@ tests/cases/conformance/classes/propertyMemberDeclarations/initializerReferencin
!!! error TS2663: Cannot find name 'x'. Did you mean the instance member 'this.x'?
b: typeof x; // error
~
!!! error TS2304: Cannot find name 'x'.
!!! error TS2844: Type of instance member variable 'b' cannot reference identifier 'x' declared in the constructor.
constructor(public x) { }
}
@@ -2,7 +2,7 @@ tests/cases/compiler/innerModExport2.ts(5,5): error TS2580: Cannot find name 'mo
tests/cases/compiler/innerModExport2.ts(5,12): error TS1437: Namespace must be given a name.
tests/cases/compiler/innerModExport2.ts(7,20): error TS2395: Individual declarations in merged declaration 'export_var' must be all exported or all local.
tests/cases/compiler/innerModExport2.ts(13,9): error TS2395: Individual declarations in merged declaration 'export_var' must be all exported or all local.
tests/cases/compiler/innerModExport2.ts(20,7): error TS2339: Property 'NonExportFunc' does not exist on type 'typeof Outer'.
tests/cases/compiler/innerModExport2.ts(20,7): error TS2551: Property 'NonExportFunc' does not exist on type 'typeof Outer'. Did you mean 'ExportFunc'?
==== tests/cases/compiler/innerModExport2.ts (5 errors) ====
@@ -35,4 +35,5 @@ tests/cases/compiler/innerModExport2.ts(20,7): error TS2339: Property 'NonExport
Outer.NonExportFunc();
~~~~~~~~~~~~~
!!! error TS2339: Property 'NonExportFunc' does not exist on type 'typeof Outer'.
!!! error TS2551: Property 'NonExportFunc' does not exist on type 'typeof Outer'. Did you mean 'ExportFunc'?
!!! related TS2728 tests/cases/compiler/innerModExport2.ts:11:25: 'ExportFunc' is declared here.
@@ -88,7 +88,7 @@
out/index.d.ts(14,39): error TS2304: Cannot find name 'class'.
out/index.d.ts(15,38): error TS2304: Cannot find name 'bool'.
out/index.d.ts(16,37): error TS2304: Cannot find name 'int'.
out/index.d.ts(17,39): error TS2304: Cannot find name 'float'.
out/index.d.ts(17,39): error TS2552: Cannot find name 'float'. Did you mean 'GLfloat'?
out/index.d.ts(18,41): error TS2304: Cannot find name 'integer'.
@@ -117,7 +117,7 @@ out/index.d.ts(18,41): error TS2304: Cannot find name 'integer'.
!!! error TS2304: Cannot find name 'int'.
/** @type {float} */ declare const o: float;
~~~~~
!!! error TS2304: Cannot find name 'float'.
!!! error TS2552: Cannot find name 'float'. Did you mean 'GLfloat'?
/** @type {integer} */ declare const p: integer;
~~~~~~~
!!! error TS2304: Cannot find name 'integer'.
@@ -1,6 +1,6 @@
tests/cases/compiler/jsxNamespacePrefixIntrinsics.tsx(15,18): error TS2339: Property 'element' does not exist on type 'JSX.IntrinsicElements'.
tests/cases/compiler/jsxNamespacePrefixIntrinsics.tsx(16,30): error TS2322: Type '{ attribute: string; }' is not assignable to type '{ "ns:attribute": string; }'.
Property 'attribute' does not exist on type '{ "ns:attribute": string; }'.
Property 'attribute' does not exist on type '{ "ns:attribute": string; }'. Did you mean '"ns:attribute"'?
tests/cases/compiler/jsxNamespacePrefixIntrinsics.tsx(17,30): error TS2322: Type '{ "ns:invalid": string; }' is not assignable to type '{ "ns:attribute": string; }'.
Property 'ns:invalid' does not exist on type '{ "ns:attribute": string; }'.
@@ -26,7 +26,7 @@ tests/cases/compiler/jsxNamespacePrefixIntrinsics.tsx(17,30): error TS2322: Type
const invalid2 = <ns:element attribute="nope" />;
~~~~~~~~~
!!! error TS2322: Type '{ attribute: string; }' is not assignable to type '{ "ns:attribute": string; }'.
!!! error TS2322: Property 'attribute' does not exist on type '{ "ns:attribute": string; }'.
!!! error TS2322: Property 'attribute' does not exist on type '{ "ns:attribute": string; }'. Did you mean '"ns:attribute"'?
const invalid3 = <ns:element ns:invalid="nope" />;
~~~~~~~~~~
!!! error TS2322: Type '{ "ns:invalid": string; }' is not assignable to type '{ "ns:attribute": string; }'.
@@ -3,7 +3,7 @@ tests/cases/conformance/parser/ecmascript5/parser15.4.4.14-9-2.ts(17,17): error
tests/cases/conformance/parser/ecmascript5/parser15.4.4.14-9-2.ts(18,17): error TS2345: Argument of type 'number' is not assignable to parameter of type 'boolean'.
tests/cases/conformance/parser/ecmascript5/parser15.4.4.14-9-2.ts(19,17): error TS2345: Argument of type 'number' is not assignable to parameter of type 'boolean'.
tests/cases/conformance/parser/ecmascript5/parser15.4.4.14-9-2.ts(20,17): error TS2345: Argument of type 'number' is not assignable to parameter of type 'boolean'.
tests/cases/conformance/parser/ecmascript5/parser15.4.4.14-9-2.ts(25,1): error TS2304: Cannot find name 'runTestCase'.
tests/cases/conformance/parser/ecmascript5/parser15.4.4.14-9-2.ts(25,1): error TS2552: Cannot find name 'runTestCase'. Did you mean 'testcase'?
==== tests/cases/conformance/parser/ecmascript5/parser15.4.4.14-9-2.ts (6 errors) ====
@@ -43,5 +43,6 @@ tests/cases/conformance/parser/ecmascript5/parser15.4.4.14-9-2.ts(25,1): error T
}
runTestCase(testcase);
~~~~~~~~~~~
!!! error TS2304: Cannot find name 'runTestCase'.
!!! error TS2552: Cannot find name 'runTestCase'. Did you mean 'testcase'?
!!! related TS2728 tests/cases/conformance/parser/ecmascript5/parser15.4.4.14-9-2.ts:12:10: 'testcase' is declared here.
@@ -5,7 +5,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource7.ts(16,37): error TS
tests/cases/conformance/parser/ecmascript5/parserRealSource7.ts(16,46): error TS1011: An element access expression should take an argument.
tests/cases/conformance/parser/ecmascript5/parserRealSource7.ts(21,36): error TS2552: Cannot find name 'TypeLink'. Did you mean 'typeLink'?
tests/cases/conformance/parser/ecmascript5/parserRealSource7.ts(29,29): error TS2304: Cannot find name 'Type'.
tests/cases/conformance/parser/ecmascript5/parserRealSource7.ts(29,45): error TS2304: Cannot find name 'TypeDeclaration'.
tests/cases/conformance/parser/ecmascript5/parserRealSource7.ts(29,45): error TS2552: Cannot find name 'TypeDeclaration'. Did you mean 'CSSStyleDeclaration'?
tests/cases/conformance/parser/ecmascript5/parserRealSource7.ts(34,43): error TS2304: Cannot find name 'Type'.
tests/cases/conformance/parser/ecmascript5/parserRealSource7.ts(34,54): error TS2304: Cannot find name 'AST'.
tests/cases/conformance/parser/ecmascript5/parserRealSource7.ts(34,68): error TS2304: Cannot find name 'TypeCollectionContext'.
@@ -351,7 +351,8 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource7.ts(828,13): error T
~~~~
!!! error TS2304: Cannot find name 'Type'.
~~~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'TypeDeclaration'.
!!! error TS2552: Cannot find name 'TypeDeclaration'. Did you mean 'CSSStyleDeclaration'?
!!! related TS2728 /.ts/lib.dom.d.ts:3275:13: 'CSSStyleDeclaration' is declared here.
type.extendsTypeLinks = getBaseTypeLinks(typeDecl.extendsList, type.extendsTypeLinks);
type.implementsTypeLinks = getBaseTypeLinks(typeDecl.implementsList, type.implementsTypeLinks);
}
@@ -1,4 +1,4 @@
tests/cases/conformance/parser/ecmascript5/RegularExpressions/parserRegularExpressionDivideAmbiguity1.ts(2,2): error TS2304: Cannot find name 'notregexp'.
tests/cases/conformance/parser/ecmascript5/RegularExpressions/parserRegularExpressionDivideAmbiguity1.ts(2,2): error TS2552: Cannot find name 'notregexp'. Did you mean 'RegExp'?
tests/cases/conformance/parser/ecmascript5/RegularExpressions/parserRegularExpressionDivideAmbiguity1.ts(2,12): error TS2304: Cannot find name 'a'.
@@ -6,6 +6,7 @@ tests/cases/conformance/parser/ecmascript5/RegularExpressions/parserRegularExpre
1
/notregexp/a.foo();
~~~~~~~~~
!!! error TS2304: Cannot find name 'notregexp'.
!!! error TS2552: Cannot find name 'notregexp'. Did you mean 'RegExp'?
!!! related TS2728 /.ts/lib.es5.d.ts:1037:13: 'RegExp' is declared here.
~
!!! error TS2304: Cannot find name 'a'.
@@ -1,10 +1,11 @@
tests/cases/conformance/parser/ecmascript5/RegularExpressions/parserRegularExpressionDivideAmbiguity2.ts(1,6): error TS2304: Cannot find name 'notregexp'.
tests/cases/conformance/parser/ecmascript5/RegularExpressions/parserRegularExpressionDivideAmbiguity2.ts(1,6): error TS2552: Cannot find name 'notregexp'. Did you mean 'RegExp'?
tests/cases/conformance/parser/ecmascript5/RegularExpressions/parserRegularExpressionDivideAmbiguity2.ts(1,16): error TS2304: Cannot find name 'a'.
==== tests/cases/conformance/parser/ecmascript5/RegularExpressions/parserRegularExpressionDivideAmbiguity2.ts (2 errors) ====
(1) /notregexp/a.foo();
~~~~~~~~~
!!! error TS2304: Cannot find name 'notregexp'.
!!! error TS2552: Cannot find name 'notregexp'. Did you mean 'RegExp'?
!!! related TS2728 /.ts/lib.es5.d.ts:1037:13: 'RegExp' is declared here.
~
!!! error TS2304: Cannot find name 'a'.
@@ -1,4 +1,4 @@
tests/cases/compiler/propertyOrdering.ts(6,23): error TS2304: Cannot find name 'store'.
tests/cases/compiler/propertyOrdering.ts(6,23): error TS2301: Initializer of instance member variable '_store' cannot reference identifier 'store' declared in the constructor.
tests/cases/compiler/propertyOrdering.ts(9,34): error TS2551: Property 'store' does not exist on type 'Foo'. Did you mean '_store'?
tests/cases/compiler/propertyOrdering.ts(16,25): error TS2339: Property '_store' does not exist on type 'Bar'.
tests/cases/compiler/propertyOrdering.ts(20,14): error TS2339: Property '_store' does not exist on type 'Bar'.
@@ -12,7 +12,7 @@ tests/cases/compiler/propertyOrdering.ts(20,14): error TS2339: Property '_store'
}
public _store = store; // no repro if this is first line in class body
~~~~~
!!! error TS2304: Cannot find name 'store'.
!!! error TS2301: Initializer of instance member variable '_store' cannot reference identifier 'store' declared in the constructor.
public bar() { return this.store; } // should be an error
@@ -1,7 +1,7 @@
tests/cases/conformance/salsa/lovefield-ts.d.ts(4,19): error TS2503: Cannot find namespace 'query'.
tests/cases/conformance/salsa/lovefield-ts.d.ts(5,24): error TS2503: Cannot find namespace 'schema'.
tests/cases/conformance/salsa/lovefield-ts.d.ts(7,25): error TS2503: Cannot find namespace 'query'.
tests/cases/conformance/salsa/lovefield-ts.d.ts(9,14): error TS2304: Cannot find name 'TransactionStats'.
tests/cases/conformance/salsa/lovefield-ts.d.ts(9,14): error TS2552: Cannot find name 'TransactionStats'. Did you mean 'Transaction'?
tests/cases/conformance/salsa/lovefield.js(3,23): error TS2694: Namespace 'lf' has no exported member 'schema'.
tests/cases/conformance/salsa/lovefield.js(4,14): error TS2304: Cannot find name 'IThenable'.
@@ -23,7 +23,8 @@ tests/cases/conformance/salsa/lovefield.js(4,14): error TS2304: Cannot find name
rollback(): Promise<void>
stats(): TransactionStats
~~~~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'TransactionStats'.
!!! error TS2552: Cannot find name 'TransactionStats'. Did you mean 'Transaction'?
!!! related TS2728 tests/cases/conformance/salsa/lovefield.js:1:1: 'Transaction' is declared here.
}
}
==== tests/cases/conformance/salsa/lovefield.js (2 errors) ====
@@ -1,9 +1,9 @@
tests/cases/compiler/recursiveTypeRelations.ts(8,5): error TS2391: Function implementation is missing or not immediately following the declaration.
tests/cases/compiler/recursiveTypeRelations.ts(27,38): error TS2304: Cannot find name 'ClassNameObject'.
tests/cases/compiler/recursiveTypeRelations.ts(27,38): error TS2552: Cannot find name 'ClassNameObject'. Did you mean 'ClassNameObjectMap'?
tests/cases/compiler/recursiveTypeRelations.ts(27,55): error TS2345: Argument of type '(obj: ClassNameObject, key: keyof S) => ClassNameObject' is not assignable to parameter of type '(previousValue: ClassNameObject, currentValue: string, currentIndex: number, array: string[]) => ClassNameObject'.
Types of parameters 'key' and 'currentValue' are incompatible.
Type 'string' is not assignable to type 'keyof S'.
tests/cases/compiler/recursiveTypeRelations.ts(27,61): error TS2304: Cannot find name 'ClassNameObject'.
tests/cases/compiler/recursiveTypeRelations.ts(27,61): error TS2552: Cannot find name 'ClassNameObject'. Did you mean 'ClassNameObjectMap'?
==== tests/cases/compiler/recursiveTypeRelations.ts (4 errors) ====
@@ -37,13 +37,13 @@ tests/cases/compiler/recursiveTypeRelations.ts(27,61): error TS2304: Cannot find
if (typeof arg == "object") {
return Object.keys(arg).reduce<ClassNameObject>((obj: ClassNameObject, key: keyof S) => {
~~~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'ClassNameObject'.
!!! error TS2552: Cannot find name 'ClassNameObject'. Did you mean 'ClassNameObjectMap'?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '(obj: ClassNameObject, key: keyof S) => ClassNameObject' is not assignable to parameter of type '(previousValue: ClassNameObject, currentValue: string, currentIndex: number, array: string[]) => ClassNameObject'.
!!! error TS2345: Types of parameters 'key' and 'currentValue' are incompatible.
!!! error TS2345: Type 'string' is not assignable to type 'keyof S'.
~~~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'ClassNameObject'.
!!! error TS2552: Cannot find name 'ClassNameObject'. Did you mean 'ClassNameObjectMap'?
const exportedClassName = styles[key];
obj[exportedClassName] = (arg as ClassNameMap<S>)[key];
return obj;
@@ -1,4 +1,4 @@
tests/cases/compiler/unspecializedConstraints.ts(84,44): error TS2304: Cannot find name 'TypeParameter'.
tests/cases/compiler/unspecializedConstraints.ts(84,44): error TS2552: Cannot find name 'TypeParameter'. Did you mean 'Parameter'?
==== tests/cases/compiler/unspecializedConstraints.ts (1 errors) ====
@@ -87,7 +87,8 @@ tests/cases/compiler/unspecializedConstraints.ts(84,44): error TS2304: Cannot fi
class Signature extends Symbol {
constructor(public typeParameters: TypeParameter[], public parameters: Parameter[], public returnType: Type) {
~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'TypeParameter'.
!!! error TS2552: Cannot find name 'TypeParameter'. Did you mean 'Parameter'?
!!! related TS2728 tests/cases/compiler/unspecializedConstraints.ts:99:11: 'Parameter' is declared here.
super();
}
equalsNoReturn(other: Signature): boolean {
@@ -0,0 +1,25 @@
/// <reference path='fourslash.ts' />
// Repro for https://github.com/microsoft/TypeScript/issues/49557
////enum NamesWithSpaces {
//// "NoSpace",
//// "One Space",
//// "Has Two Spaces",
//// "This Has Three Spaces",
//// "And This Has Four Spaces",
////
//// "Block One",
//// "Block Two",
//// "Block Three",
////
//// "This Has Three Spaces_________________________________________________________",
//// "And This Has Four Spaces_________________________________________________________",
////}
////
//// NamesWithSpaces.[|ThisHasThreeSpaces|];
verify.codeFixAvailable([
{ description: "Change spelling to 'This Has Three Spaces'" },
{ description: "Add missing enum member 'ThisHasThreeSpaces'" },
]);
@@ -0,0 +1,25 @@
/// <reference path='fourslash.ts' />
// Repro for https://github.com/microsoft/TypeScript/issues/49557
////enum NamesWithSpaces {
//// "NoSpace",
//// "One Space",
//// "Has Two Spaces",
//// "This Has Three Spaces",
//// "And This Has Four Spaces",
////
//// "Block One",
//// "Block Two",
//// "Block Three",
////
//// "This Has Three Spaces_________________________________________________________",
//// "And This Has Four Spaces_________________________________________________________",
////}
////
//// NamesWithSpaces.[|AndThisHasFourSpaces|];
verify.codeFixAvailable([
{ description: "Change spelling to 'And This Has Four Spaces'" },
{ description: "Add missing enum member 'AndThisHasFourSpaces'" },
]);
@@ -0,0 +1,25 @@
/// <reference path='fourslash.ts' />
// Repro for https://github.com/microsoft/TypeScript/issues/49557
////enum NamesWithSpaces {
//// "NoSpace",
//// "One Space",
//// "Has Two Spaces",
//// "This Has Three Spaces",
//// "And This Has Four Spaces",
////
//// "Block One",
//// "Block Two",
//// "Block Three",
////
//// "This Has Three Spaces_________________________________________________________",
//// "And This Has Four Spaces_________________________________________________________",
////}
////
//// NamesWithSpaces.[|BlockThree|];
verify.codeFixAvailable([
{ description: "Change spelling to 'Block Three'" },
{ description: "Add missing enum member 'BlockThree'" },
]);
@@ -0,0 +1,25 @@
/// <reference path='fourslash.ts' />
// Repro for https://github.com/microsoft/TypeScript/issues/49557
////enum NamesWithSpaces {
//// "NoSpace",
//// "One Space",
//// "Has Two Spaces",
//// "This Has Three Spaces",
//// "And This Has Four Spaces",
////
//// "Block One",
//// "Block Two",
//// "Block Three",
////
//// "This Has Three Spaces_________________________________________________________",
//// "And This Has Four Spaces_________________________________________________________",
////}
////
//// NamesWithSpaces.[|ThisHasThreeSpaces_________________________________________________________|];
verify.codeFixAvailable([
{ description: "Change spelling to 'This Has Three Spaces_________________________________________________________'" },
{ description: "Add missing enum member 'ThisHasThreeSpaces_________________________________________________________'" },
]);
@@ -0,0 +1,25 @@
/// <reference path='fourslash.ts' />
// Repro for https://github.com/microsoft/TypeScript/issues/49557
////enum NamesWithSpaces {
//// "NoSpace",
//// "One Space",
//// "Has Two Spaces",
//// "This Has Three Spaces",
//// "And This Has Four Spaces",
////
//// "Block One",
//// "Block Two",
//// "Block Three",
////
//// "This Has Three Spaces_________________________________________________________",
//// "And This Has Four Spaces_________________________________________________________",
////}
////
//// NamesWithSpaces.[|AndThisHasFourSpaces_________________________________________________________|];
verify.codeFixAvailable([
{ description: "Change spelling to 'And This Has Four Spaces_________________________________________________________'" },
{ description: "Add missing enum member 'AndThisHasFourSpaces_________________________________________________________'" },
]);