mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 11:54:44 -06:00
Allow accessors in ambient classes
This commit is contained in:
parent
f333684179
commit
37c4f24ef3
@ -5935,7 +5935,9 @@ namespace ts {
|
||||
// Otherwise, fall back to 'any'.
|
||||
else {
|
||||
if (setter) {
|
||||
errorOrSuggestion(noImplicitAny, setter, Diagnostics.Property_0_implicitly_has_type_any_because_its_set_accessor_lacks_a_parameter_type_annotation, symbolToString(symbol));
|
||||
if (!isPrivateWithinAmbient(setter)) {
|
||||
errorOrSuggestion(noImplicitAny, setter, Diagnostics.Property_0_implicitly_has_type_any_because_its_set_accessor_lacks_a_parameter_type_annotation, symbolToString(symbol));
|
||||
}
|
||||
}
|
||||
else {
|
||||
Debug.assert(!!getter, "there must existed getter as we are current checking either setter or getter in this function");
|
||||
@ -33039,10 +33041,7 @@ namespace ts {
|
||||
if (languageVersion < ScriptTarget.ES5) {
|
||||
return grammarErrorOnNode(accessor.name, Diagnostics.Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher);
|
||||
}
|
||||
else if (accessor.flags & NodeFlags.Ambient) {
|
||||
return grammarErrorOnNode(accessor.name, Diagnostics.An_accessor_cannot_be_declared_in_an_ambient_context);
|
||||
}
|
||||
else if (accessor.body === undefined && !hasModifier(accessor, ModifierFlags.Abstract)) {
|
||||
else if (accessor.body === undefined && !hasModifier(accessor, ModifierFlags.Abstract) && !(accessor.flags & NodeFlags.Ambient)) {
|
||||
return grammarErrorAtPos(accessor, accessor.end - 1, ";".length, Diagnostics._0_expected, "{");
|
||||
}
|
||||
else if (accessor.body && hasModifier(accessor, ModifierFlags.Abstract)) {
|
||||
|
||||
@ -243,10 +243,6 @@
|
||||
"category": "Error",
|
||||
"code": 1085
|
||||
},
|
||||
"An accessor cannot be declared in an ambient context.": {
|
||||
"category": "Error",
|
||||
"code": 1086
|
||||
},
|
||||
"'{0}' modifier cannot appear on a constructor declaration.": {
|
||||
"category": "Error",
|
||||
"code": 1089
|
||||
|
||||
@ -1,44 +0,0 @@
|
||||
tests/cases/compiler/accessorsInAmbientContext.ts(3,13): error TS1086: An accessor cannot be declared in an ambient context.
|
||||
tests/cases/compiler/accessorsInAmbientContext.ts(4,13): error TS1086: An accessor cannot be declared in an ambient context.
|
||||
tests/cases/compiler/accessorsInAmbientContext.ts(6,20): error TS1086: An accessor cannot be declared in an ambient context.
|
||||
tests/cases/compiler/accessorsInAmbientContext.ts(7,20): error TS1086: An accessor cannot be declared in an ambient context.
|
||||
tests/cases/compiler/accessorsInAmbientContext.ts(12,9): error TS1086: An accessor cannot be declared in an ambient context.
|
||||
tests/cases/compiler/accessorsInAmbientContext.ts(13,9): error TS1086: An accessor cannot be declared in an ambient context.
|
||||
tests/cases/compiler/accessorsInAmbientContext.ts(15,16): error TS1086: An accessor cannot be declared in an ambient context.
|
||||
tests/cases/compiler/accessorsInAmbientContext.ts(16,16): error TS1086: An accessor cannot be declared in an ambient context.
|
||||
|
||||
|
||||
==== tests/cases/compiler/accessorsInAmbientContext.ts (8 errors) ====
|
||||
declare module M {
|
||||
class C {
|
||||
get X() { return 1; }
|
||||
~
|
||||
!!! error TS1086: An accessor cannot be declared in an ambient context.
|
||||
set X(v) { }
|
||||
~
|
||||
!!! error TS1086: An accessor cannot be declared in an ambient context.
|
||||
|
||||
static get Y() { return 1; }
|
||||
~
|
||||
!!! error TS1086: An accessor cannot be declared in an ambient context.
|
||||
static set Y(v) { }
|
||||
~
|
||||
!!! error TS1086: An accessor cannot be declared in an ambient context.
|
||||
}
|
||||
}
|
||||
|
||||
declare class C {
|
||||
get X() { return 1; }
|
||||
~
|
||||
!!! error TS1086: An accessor cannot be declared in an ambient context.
|
||||
set X(v) { }
|
||||
~
|
||||
!!! error TS1086: An accessor cannot be declared in an ambient context.
|
||||
|
||||
static get Y() { return 1; }
|
||||
~
|
||||
!!! error TS1086: An accessor cannot be declared in an ambient context.
|
||||
static set Y(v) { }
|
||||
~
|
||||
!!! error TS1086: An accessor cannot be declared in an ambient context.
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
tests/cases/compiler/ambientGetters.ts(2,9): error TS1086: An accessor cannot be declared in an ambient context.
|
||||
tests/cases/compiler/ambientGetters.ts(6,9): error TS1086: An accessor cannot be declared in an ambient context.
|
||||
|
||||
|
||||
==== tests/cases/compiler/ambientGetters.ts (2 errors) ====
|
||||
declare class A {
|
||||
get length() : number;
|
||||
~~~~~~
|
||||
!!! error TS1086: An accessor cannot be declared in an ambient context.
|
||||
}
|
||||
|
||||
declare class B {
|
||||
get length() { return 0; }
|
||||
~~~~~~
|
||||
!!! error TS1086: An accessor cannot be declared in an ambient context.
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
tests/cases/conformance/parser/ecmascript5/Accessors/parserAccessors5.ts(2,7): error TS1086: An accessor cannot be declared in an ambient context.
|
||||
|
||||
|
||||
==== tests/cases/conformance/parser/ecmascript5/Accessors/parserAccessors5.ts (1 errors) ====
|
||||
declare class C {
|
||||
get foo() { return 0; }
|
||||
~~~
|
||||
!!! error TS1086: An accessor cannot be declared in an ambient context.
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
tests/cases/conformance/parser/ecmascript5/Accessors/parserAccessors6.ts(2,7): error TS1086: An accessor cannot be declared in an ambient context.
|
||||
|
||||
|
||||
==== tests/cases/conformance/parser/ecmascript5/Accessors/parserAccessors6.ts (1 errors) ====
|
||||
declare class C {
|
||||
set foo(v) { }
|
||||
~~~
|
||||
!!! error TS1086: An accessor cannot be declared in an ambient context.
|
||||
}
|
||||
@ -1,12 +1,9 @@
|
||||
tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName23.ts(2,9): error TS1086: An accessor cannot be declared in an ambient context.
|
||||
tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName23.ts(2,10): error TS2304: Cannot find name 'e'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName23.ts (2 errors) ====
|
||||
==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName23.ts (1 errors) ====
|
||||
declare class C {
|
||||
get [e](): number
|
||||
~~~
|
||||
!!! error TS1086: An accessor cannot be declared in an ambient context.
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'e'.
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user