mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Allow getter and setter types to be unrelated (#53417)
This commit is contained in:
@@ -38507,12 +38507,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
error(getter.name, Diagnostics.A_get_accessor_must_be_at_least_as_accessible_as_the_setter);
|
||||
error(setter.name, Diagnostics.A_get_accessor_must_be_at_least_as_accessible_as_the_setter);
|
||||
}
|
||||
|
||||
const getterType = getAnnotatedAccessorType(getter);
|
||||
const setterType = getAnnotatedAccessorType(setter);
|
||||
if (getterType && setterType) {
|
||||
checkTypeAssignableTo(getterType, setterType, getter, Diagnostics.The_return_type_of_a_get_accessor_must_be_assignable_to_its_set_accessor_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
const returnType = getTypeOfAccessors(getSymbolOfDeclaration(node));
|
||||
|
||||
@@ -1972,10 +1972,6 @@
|
||||
"category": "Error",
|
||||
"code": 2379
|
||||
},
|
||||
"The return type of a 'get' accessor must be assignable to its 'set' accessor type": {
|
||||
"category": "Error",
|
||||
"code": 2380
|
||||
},
|
||||
"Overload signatures must all be exported or non-exported.": {
|
||||
"category": "Error",
|
||||
"code": 2383
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
tests/cases/compiler/abstractPropertyNegative.ts(10,18): error TS2380: The return type of a 'get' accessor must be assignable to its 'set' accessor type
|
||||
tests/cases/compiler/abstractPropertyNegative.ts(13,7): error TS18052: Non-abstract class 'C' does not implement all abstract members of 'B'
|
||||
tests/cases/compiler/abstractPropertyNegative.ts(15,5): error TS1253: Abstract properties can only appear within an abstract class.
|
||||
tests/cases/compiler/abstractPropertyNegative.ts(16,37): error TS1005: '{' expected.
|
||||
@@ -15,7 +14,7 @@ tests/cases/compiler/abstractPropertyNegative.ts(40,9): error TS2676: Accessors
|
||||
tests/cases/compiler/abstractPropertyNegative.ts(41,18): error TS2676: Accessors must both be abstract or non-abstract.
|
||||
|
||||
|
||||
==== tests/cases/compiler/abstractPropertyNegative.ts (12 errors) ====
|
||||
==== tests/cases/compiler/abstractPropertyNegative.ts (11 errors) ====
|
||||
interface A {
|
||||
prop: string;
|
||||
m(): string;
|
||||
@@ -26,9 +25,7 @@ tests/cases/compiler/abstractPropertyNegative.ts(41,18): error TS2676: Accessors
|
||||
abstract get readonlyProp(): string;
|
||||
abstract m(): string;
|
||||
abstract get mismatch(): string;
|
||||
~~~~~~~~
|
||||
!!! error TS2380: The return type of a 'get' accessor must be assignable to its 'set' accessor type
|
||||
abstract set mismatch(val: number); // error, not same type
|
||||
abstract set mismatch(val: number);
|
||||
}
|
||||
class C extends B {
|
||||
~
|
||||
|
||||
@@ -9,7 +9,7 @@ abstract class B implements A {
|
||||
abstract get readonlyProp(): string;
|
||||
abstract m(): string;
|
||||
abstract get mismatch(): string;
|
||||
abstract set mismatch(val: number); // error, not same type
|
||||
abstract set mismatch(val: number);
|
||||
}
|
||||
class C extends B {
|
||||
readonly ro = "readonly please";
|
||||
|
||||
@@ -27,7 +27,7 @@ abstract class B implements A {
|
||||
abstract get mismatch(): string;
|
||||
>mismatch : Symbol(B.mismatch, Decl(abstractPropertyNegative.ts, 8, 25), Decl(abstractPropertyNegative.ts, 9, 36))
|
||||
|
||||
abstract set mismatch(val: number); // error, not same type
|
||||
abstract set mismatch(val: number);
|
||||
>mismatch : Symbol(B.mismatch, Decl(abstractPropertyNegative.ts, 8, 25), Decl(abstractPropertyNegative.ts, 9, 36))
|
||||
>val : Symbol(val, Decl(abstractPropertyNegative.ts, 10, 26))
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ abstract class B implements A {
|
||||
abstract get mismatch(): string;
|
||||
>mismatch : string
|
||||
|
||||
abstract set mismatch(val: number); // error, not same type
|
||||
abstract set mismatch(val: number);
|
||||
>mismatch : string
|
||||
>val : number
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
tests/cases/compiler/divergentAccessorsTypes6.ts(11,1): error TS2322: Type 'CSSStyleDeclaration' is not assignable to type 'string'.
|
||||
tests/cases/compiler/divergentAccessorsTypes6.ts(19,23): error TS2344: Type 'string' does not satisfy the constraint 'never'.
|
||||
tests/cases/compiler/divergentAccessorsTypes6.ts(23,23): error TS2344: Type 'string' does not satisfy the constraint 'never'.
|
||||
tests/cases/compiler/divergentAccessorsTypes6.ts(29,16): error TS2322: Type 'number' is not assignable to type 'string'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/divergentAccessorsTypes6.ts (4 errors) ====
|
||||
export {};
|
||||
|
||||
interface Element {
|
||||
get style(): CSSStyleDeclaration;
|
||||
set style(cssText: string);
|
||||
}
|
||||
|
||||
declare const element: Element;
|
||||
element.style = "color: red";
|
||||
element.style.animationTimingFunction;
|
||||
element.style = element.style; // error
|
||||
~~~~~~~~~~~~~
|
||||
!!! error TS2322: Type 'CSSStyleDeclaration' is not assignable to type 'string'.
|
||||
|
||||
// Now that we don't check for getter/setter assignability, we should
|
||||
// ensure the setter annotation is actually checked even if it's never observed.
|
||||
|
||||
type Fail<T extends never> = T;
|
||||
interface I1 {
|
||||
get x(): number;
|
||||
set x(value: Fail<string>);
|
||||
~~~~~~
|
||||
!!! error TS2344: Type 'string' does not satisfy the constraint 'never'.
|
||||
}
|
||||
const o1 = {
|
||||
get x(): number { return 0; },
|
||||
set x(value: Fail<string>) {}
|
||||
~~~~~~
|
||||
!!! error TS2344: Type 'string' does not satisfy the constraint 'never'.
|
||||
}
|
||||
|
||||
// A setter annotation still implies the getter return type.
|
||||
|
||||
const o2 = {
|
||||
get p1() { return 0; }, // error - no annotation means type is implied from the setter annotation
|
||||
~~~~~~
|
||||
!!! error TS2322: Type 'number' is not assignable to type 'string'.
|
||||
set p1(value: string) {},
|
||||
|
||||
get p2(): number { return 0; }, // ok - explicit annotation
|
||||
set p2(value: string) {},
|
||||
};
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
//// [divergentAccessorsTypes6.ts]
|
||||
export {};
|
||||
|
||||
interface Element {
|
||||
get style(): CSSStyleDeclaration;
|
||||
set style(cssText: string);
|
||||
}
|
||||
|
||||
declare const element: Element;
|
||||
element.style = "color: red";
|
||||
element.style.animationTimingFunction;
|
||||
element.style = element.style; // error
|
||||
|
||||
// Now that we don't check for getter/setter assignability, we should
|
||||
// ensure the setter annotation is actually checked even if it's never observed.
|
||||
|
||||
type Fail<T extends never> = T;
|
||||
interface I1 {
|
||||
get x(): number;
|
||||
set x(value: Fail<string>);
|
||||
}
|
||||
const o1 = {
|
||||
get x(): number { return 0; },
|
||||
set x(value: Fail<string>) {}
|
||||
}
|
||||
|
||||
// A setter annotation still implies the getter return type.
|
||||
|
||||
const o2 = {
|
||||
get p1() { return 0; }, // error - no annotation means type is implied from the setter annotation
|
||||
set p1(value: string) {},
|
||||
|
||||
get p2(): number { return 0; }, // ok - explicit annotation
|
||||
set p2(value: string) {},
|
||||
};
|
||||
|
||||
|
||||
//// [divergentAccessorsTypes6.js]
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
element.style = "color: red";
|
||||
element.style.animationTimingFunction;
|
||||
element.style = element.style; // error
|
||||
var o1 = {
|
||||
get x() { return 0; },
|
||||
set x(value) { }
|
||||
};
|
||||
// A setter annotation still implies the getter return type.
|
||||
var o2 = {
|
||||
get p1() { return 0; },
|
||||
set p1(value) { },
|
||||
get p2() { return 0; },
|
||||
set p2(value) { },
|
||||
};
|
||||
|
||||
|
||||
//// [divergentAccessorsTypes6.d.ts]
|
||||
export {};
|
||||
@@ -0,0 +1,91 @@
|
||||
=== tests/cases/compiler/divergentAccessorsTypes6.ts ===
|
||||
export {};
|
||||
|
||||
interface Element {
|
||||
>Element : Symbol(Element, Decl(divergentAccessorsTypes6.ts, 0, 10))
|
||||
|
||||
get style(): CSSStyleDeclaration;
|
||||
>style : Symbol(Element.style, Decl(divergentAccessorsTypes6.ts, 2, 19), Decl(divergentAccessorsTypes6.ts, 3, 37))
|
||||
>CSSStyleDeclaration : Symbol(CSSStyleDeclaration, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))
|
||||
|
||||
set style(cssText: string);
|
||||
>style : Symbol(Element.style, Decl(divergentAccessorsTypes6.ts, 2, 19), Decl(divergentAccessorsTypes6.ts, 3, 37))
|
||||
>cssText : Symbol(cssText, Decl(divergentAccessorsTypes6.ts, 4, 14))
|
||||
}
|
||||
|
||||
declare const element: Element;
|
||||
>element : Symbol(element, Decl(divergentAccessorsTypes6.ts, 7, 13))
|
||||
>Element : Symbol(Element, Decl(divergentAccessorsTypes6.ts, 0, 10))
|
||||
|
||||
element.style = "color: red";
|
||||
>element.style : Symbol(Element.style, Decl(divergentAccessorsTypes6.ts, 2, 19), Decl(divergentAccessorsTypes6.ts, 3, 37))
|
||||
>element : Symbol(element, Decl(divergentAccessorsTypes6.ts, 7, 13))
|
||||
>style : Symbol(Element.style, Decl(divergentAccessorsTypes6.ts, 2, 19), Decl(divergentAccessorsTypes6.ts, 3, 37))
|
||||
|
||||
element.style.animationTimingFunction;
|
||||
>element.style.animationTimingFunction : Symbol(CSSStyleDeclaration.animationTimingFunction, Decl(lib.dom.d.ts, --, --))
|
||||
>element.style : Symbol(Element.style, Decl(divergentAccessorsTypes6.ts, 2, 19), Decl(divergentAccessorsTypes6.ts, 3, 37))
|
||||
>element : Symbol(element, Decl(divergentAccessorsTypes6.ts, 7, 13))
|
||||
>style : Symbol(Element.style, Decl(divergentAccessorsTypes6.ts, 2, 19), Decl(divergentAccessorsTypes6.ts, 3, 37))
|
||||
>animationTimingFunction : Symbol(CSSStyleDeclaration.animationTimingFunction, Decl(lib.dom.d.ts, --, --))
|
||||
|
||||
element.style = element.style; // error
|
||||
>element.style : Symbol(Element.style, Decl(divergentAccessorsTypes6.ts, 2, 19), Decl(divergentAccessorsTypes6.ts, 3, 37))
|
||||
>element : Symbol(element, Decl(divergentAccessorsTypes6.ts, 7, 13))
|
||||
>style : Symbol(Element.style, Decl(divergentAccessorsTypes6.ts, 2, 19), Decl(divergentAccessorsTypes6.ts, 3, 37))
|
||||
>element.style : Symbol(Element.style, Decl(divergentAccessorsTypes6.ts, 2, 19), Decl(divergentAccessorsTypes6.ts, 3, 37))
|
||||
>element : Symbol(element, Decl(divergentAccessorsTypes6.ts, 7, 13))
|
||||
>style : Symbol(Element.style, Decl(divergentAccessorsTypes6.ts, 2, 19), Decl(divergentAccessorsTypes6.ts, 3, 37))
|
||||
|
||||
// Now that we don't check for getter/setter assignability, we should
|
||||
// ensure the setter annotation is actually checked even if it's never observed.
|
||||
|
||||
type Fail<T extends never> = T;
|
||||
>Fail : Symbol(Fail, Decl(divergentAccessorsTypes6.ts, 10, 30))
|
||||
>T : Symbol(T, Decl(divergentAccessorsTypes6.ts, 15, 10))
|
||||
>T : Symbol(T, Decl(divergentAccessorsTypes6.ts, 15, 10))
|
||||
|
||||
interface I1 {
|
||||
>I1 : Symbol(I1, Decl(divergentAccessorsTypes6.ts, 15, 31))
|
||||
|
||||
get x(): number;
|
||||
>x : Symbol(I1.x, Decl(divergentAccessorsTypes6.ts, 16, 14), Decl(divergentAccessorsTypes6.ts, 17, 20))
|
||||
|
||||
set x(value: Fail<string>);
|
||||
>x : Symbol(I1.x, Decl(divergentAccessorsTypes6.ts, 16, 14), Decl(divergentAccessorsTypes6.ts, 17, 20))
|
||||
>value : Symbol(value, Decl(divergentAccessorsTypes6.ts, 18, 10))
|
||||
>Fail : Symbol(Fail, Decl(divergentAccessorsTypes6.ts, 10, 30))
|
||||
}
|
||||
const o1 = {
|
||||
>o1 : Symbol(o1, Decl(divergentAccessorsTypes6.ts, 20, 5))
|
||||
|
||||
get x(): number { return 0; },
|
||||
>x : Symbol(x, Decl(divergentAccessorsTypes6.ts, 20, 12), Decl(divergentAccessorsTypes6.ts, 21, 34))
|
||||
|
||||
set x(value: Fail<string>) {}
|
||||
>x : Symbol(x, Decl(divergentAccessorsTypes6.ts, 20, 12), Decl(divergentAccessorsTypes6.ts, 21, 34))
|
||||
>value : Symbol(value, Decl(divergentAccessorsTypes6.ts, 22, 10))
|
||||
>Fail : Symbol(Fail, Decl(divergentAccessorsTypes6.ts, 10, 30))
|
||||
}
|
||||
|
||||
// A setter annotation still implies the getter return type.
|
||||
|
||||
const o2 = {
|
||||
>o2 : Symbol(o2, Decl(divergentAccessorsTypes6.ts, 27, 5))
|
||||
|
||||
get p1() { return 0; }, // error - no annotation means type is implied from the setter annotation
|
||||
>p1 : Symbol(p1, Decl(divergentAccessorsTypes6.ts, 27, 12), Decl(divergentAccessorsTypes6.ts, 28, 27))
|
||||
|
||||
set p1(value: string) {},
|
||||
>p1 : Symbol(p1, Decl(divergentAccessorsTypes6.ts, 27, 12), Decl(divergentAccessorsTypes6.ts, 28, 27))
|
||||
>value : Symbol(value, Decl(divergentAccessorsTypes6.ts, 29, 11))
|
||||
|
||||
get p2(): number { return 0; }, // ok - explicit annotation
|
||||
>p2 : Symbol(p2, Decl(divergentAccessorsTypes6.ts, 29, 29), Decl(divergentAccessorsTypes6.ts, 31, 35))
|
||||
|
||||
set p2(value: string) {},
|
||||
>p2 : Symbol(p2, Decl(divergentAccessorsTypes6.ts, 29, 29), Decl(divergentAccessorsTypes6.ts, 31, 35))
|
||||
>value : Symbol(value, Decl(divergentAccessorsTypes6.ts, 32, 11))
|
||||
|
||||
};
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
=== tests/cases/compiler/divergentAccessorsTypes6.ts ===
|
||||
export {};
|
||||
|
||||
interface Element {
|
||||
get style(): CSSStyleDeclaration;
|
||||
>style : CSSStyleDeclaration
|
||||
|
||||
set style(cssText: string);
|
||||
>style : CSSStyleDeclaration
|
||||
>cssText : string
|
||||
}
|
||||
|
||||
declare const element: Element;
|
||||
>element : Element
|
||||
|
||||
element.style = "color: red";
|
||||
>element.style = "color: red" : "color: red"
|
||||
>element.style : string
|
||||
>element : Element
|
||||
>style : string
|
||||
>"color: red" : "color: red"
|
||||
|
||||
element.style.animationTimingFunction;
|
||||
>element.style.animationTimingFunction : string
|
||||
>element.style : CSSStyleDeclaration
|
||||
>element : Element
|
||||
>style : CSSStyleDeclaration
|
||||
>animationTimingFunction : string
|
||||
|
||||
element.style = element.style; // error
|
||||
>element.style = element.style : CSSStyleDeclaration
|
||||
>element.style : string
|
||||
>element : Element
|
||||
>style : string
|
||||
>element.style : CSSStyleDeclaration
|
||||
>element : Element
|
||||
>style : CSSStyleDeclaration
|
||||
|
||||
// Now that we don't check for getter/setter assignability, we should
|
||||
// ensure the setter annotation is actually checked even if it's never observed.
|
||||
|
||||
type Fail<T extends never> = T;
|
||||
>Fail : T
|
||||
|
||||
interface I1 {
|
||||
get x(): number;
|
||||
>x : number
|
||||
|
||||
set x(value: Fail<string>);
|
||||
>x : number
|
||||
>value : string
|
||||
}
|
||||
const o1 = {
|
||||
>o1 : { x: number; }
|
||||
>{ get x(): number { return 0; }, set x(value: Fail<string>) {}} : { x: number; }
|
||||
|
||||
get x(): number { return 0; },
|
||||
>x : number
|
||||
>0 : 0
|
||||
|
||||
set x(value: Fail<string>) {}
|
||||
>x : number
|
||||
>value : string
|
||||
}
|
||||
|
||||
// A setter annotation still implies the getter return type.
|
||||
|
||||
const o2 = {
|
||||
>o2 : { p1: string; p2: number; }
|
||||
>{ get p1() { return 0; }, // error - no annotation means type is implied from the setter annotation set p1(value: string) {}, get p2(): number { return 0; }, // ok - explicit annotation set p2(value: string) {},} : { p1: string; p2: number; }
|
||||
|
||||
get p1() { return 0; }, // error - no annotation means type is implied from the setter annotation
|
||||
>p1 : string
|
||||
>0 : 0
|
||||
|
||||
set p1(value: string) {},
|
||||
>p1 : string
|
||||
>value : string
|
||||
|
||||
get p2(): number { return 0; }, // ok - explicit annotation
|
||||
>p2 : number
|
||||
>0 : 0
|
||||
|
||||
set p2(value: string) {},
|
||||
>p2 : number
|
||||
>value : string
|
||||
|
||||
};
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
tests/cases/compiler/getAndSetNotIdenticalType.ts(2,9): error TS2380: The return type of a 'get' accessor must be assignable to its 'set' accessor type
|
||||
|
||||
|
||||
==== tests/cases/compiler/getAndSetNotIdenticalType.ts (1 errors) ====
|
||||
class C {
|
||||
get x(): number {
|
||||
~
|
||||
!!! error TS2380: The return type of a 'get' accessor must be assignable to its 'set' accessor type
|
||||
return 1;
|
||||
}
|
||||
set x(v: string) { }
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
tests/cases/compiler/getAndSetNotIdenticalType2.ts(5,9): error TS2380: The return type of a 'get' accessor must be assignable to its 'set' accessor type
|
||||
Type 'T' is not assignable to type 'string'.
|
||||
tests/cases/compiler/getAndSetNotIdenticalType2.ts(9,9): error TS2322: Type 'A<string>' is not assignable to type 'A<T>'.
|
||||
Type 'string' is not assignable to type 'T'.
|
||||
'T' could be instantiated with an arbitrary type which could be unrelated to 'string'.
|
||||
@@ -7,16 +5,12 @@ tests/cases/compiler/getAndSetNotIdenticalType2.ts(15,1): error TS2322: Type 'A<
|
||||
Type 'unknown' is not assignable to type 'string'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/getAndSetNotIdenticalType2.ts (3 errors) ====
|
||||
==== tests/cases/compiler/getAndSetNotIdenticalType2.ts (2 errors) ====
|
||||
class A<T> { foo: T; }
|
||||
|
||||
class C<T> {
|
||||
data: A<T>;
|
||||
get x(): A<T> {
|
||||
~
|
||||
!!! error TS2380: The return type of a 'get' accessor must be assignable to its 'set' accessor type
|
||||
!!! error TS2380: Type 'T' is not assignable to type 'string'.
|
||||
!!! related TS2208 tests/cases/compiler/getAndSetNotIdenticalType2.ts:3:9: This type parameter might need an `extends string` constraint.
|
||||
return this.data;
|
||||
}
|
||||
set x(v: A<string>) {
|
||||
|
||||
@@ -1,19 +1,15 @@
|
||||
tests/cases/compiler/getAndSetNotIdenticalType3.ts(5,9): error TS2380: The return type of a 'get' accessor must be assignable to its 'set' accessor type
|
||||
Type 'number' is not assignable to type 'string'.
|
||||
tests/cases/compiler/getAndSetNotIdenticalType3.ts(9,9): error TS2322: Type 'A<string>' is not assignable to type 'A<number>'.
|
||||
Type 'string' is not assignable to type 'number'.
|
||||
tests/cases/compiler/getAndSetNotIdenticalType3.ts(15,1): error TS2322: Type 'A<number>' is not assignable to type 'A<string>'.
|
||||
Type 'number' is not assignable to type 'string'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/getAndSetNotIdenticalType3.ts (3 errors) ====
|
||||
==== tests/cases/compiler/getAndSetNotIdenticalType3.ts (2 errors) ====
|
||||
class A<T> { foo: T; }
|
||||
|
||||
class C<T> {
|
||||
data: A<number>;
|
||||
get x(): A<number> {
|
||||
~
|
||||
!!! error TS2380: The return type of a 'get' accessor must be assignable to its 'set' accessor type
|
||||
!!! error TS2380: Type 'number' is not assignable to type 'string'.
|
||||
return this.data;
|
||||
}
|
||||
set x(v: A<string>) {
|
||||
@@ -28,4 +24,5 @@ tests/cases/compiler/getAndSetNotIdenticalType3.ts(15,1): error TS2322: Type 'A<
|
||||
var r = x.x;
|
||||
x.x = r;
|
||||
~~~
|
||||
!!! error TS2322: Type 'A<number>' is not assignable to type 'A<string>'.
|
||||
!!! error TS2322: Type 'A<number>' is not assignable to type 'A<string>'.
|
||||
!!! error TS2322: Type 'number' is not assignable to type 'string'.
|
||||
@@ -1,22 +0,0 @@
|
||||
tests/cases/compiler/getterErrorMessageNotDuplicated.ts(2,9): error TS2380: The return type of a 'get' accessor must be assignable to its 'set' accessor type
|
||||
Property 'extra' is missing in type 'Foo' but required in type 'Bar'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/getterErrorMessageNotDuplicated.ts (1 errors) ====
|
||||
interface Thing {
|
||||
get style(): Foo;
|
||||
~~~~~
|
||||
!!! error TS2380: The return type of a 'get' accessor must be assignable to its 'set' accessor type
|
||||
!!! error TS2380: Property 'extra' is missing in type 'Foo' but required in type 'Bar'.
|
||||
!!! related TS2728 tests/cases/compiler/getterErrorMessageNotDuplicated.ts:12:5: 'extra' is declared here.
|
||||
set style(cssText: string | Bar);
|
||||
}
|
||||
|
||||
interface Foo {
|
||||
hello: string;
|
||||
world: number;
|
||||
}
|
||||
|
||||
interface Bar extends Foo {
|
||||
extra: any;
|
||||
}
|
||||
@@ -70,15 +70,13 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(38,26)
|
||||
tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(39,13): error TS2300: Duplicate identifier 'a'.
|
||||
tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(39,46): error TS1119: An object literal cannot have property and accessor with the same name.
|
||||
tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(39,46): error TS2300: Duplicate identifier 'a'.
|
||||
tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(42,16): error TS2380: The return type of a 'get' accessor must be assignable to its 'set' accessor type
|
||||
tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(43,22): error TS2322: Type 'number' is not assignable to type 'string'.
|
||||
tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(44,16): error TS2380: The return type of a 'get' accessor must be assignable to its 'set' accessor type
|
||||
tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(48,7): error TS1312: Did you mean to use a ':'? An '=' can only follow a property name when the containing object literal is part of a destructuring pattern.
|
||||
tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(49,7): error TS1312: Did you mean to use a ':'? An '=' can only follow a property name when the containing object literal is part of a destructuring pattern.
|
||||
tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(50,5): error TS18016: Private identifiers are not allowed outside class bodies.
|
||||
|
||||
|
||||
==== tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts (78 errors) ====
|
||||
==== tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts (76 errors) ====
|
||||
// Multiple properties with the same name
|
||||
var e1 = { a: 0, a: 0 };
|
||||
~
|
||||
@@ -263,16 +261,12 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(50,5):
|
||||
~
|
||||
!!! error TS2300: Duplicate identifier 'a'.
|
||||
|
||||
// Get and set accessor with mismatched type annotations
|
||||
// Get and set accessor with mismatched type annotations (only g2 is an error after #43662 implemented)
|
||||
var g1 = { get a(): number { return 4; }, set a(n: string) { } };
|
||||
~
|
||||
!!! error TS2380: The return type of a 'get' accessor must be assignable to its 'set' accessor type
|
||||
var g2 = { get a() { return 4; }, set a(n: string) { } };
|
||||
~~~~~~
|
||||
!!! error TS2322: Type 'number' is not assignable to type 'string'.
|
||||
var g3 = { get a(): number { return undefined; }, set a(n: string) { } };
|
||||
~
|
||||
!!! error TS2380: The return type of a 'get' accessor must be assignable to its 'set' accessor type
|
||||
|
||||
// did you mean colon errors
|
||||
var h1 = {
|
||||
|
||||
@@ -39,7 +39,7 @@ var f15 = { "100": 0, get 1e2() { return 0; } };
|
||||
var f16 = { 0x20: 0, get 3.2e1() { return 0; } };
|
||||
var f17 = { a: 0, get b() { return 1; }, get a() { return 0; } };
|
||||
|
||||
// Get and set accessor with mismatched type annotations
|
||||
// Get and set accessor with mismatched type annotations (only g2 is an error after #43662 implemented)
|
||||
var g1 = { get a(): number { return 4; }, set a(n: string) { } };
|
||||
var g2 = { get a() { return 4; }, set a(n: string) { } };
|
||||
var g3 = { get a(): number { return undefined; }, set a(n: string) { } };
|
||||
@@ -91,7 +91,7 @@ var f14 = { 0: 0, get 0o0() { return 0; } };
|
||||
var f15 = { "100": 0, get 1e2() { return 0; } };
|
||||
var f16 = { 0x20: 0, get 3.2e1() { return 0; } };
|
||||
var f17 = { a: 0, get b() { return 1; }, get a() { return 0; } };
|
||||
// Get and set accessor with mismatched type annotations
|
||||
// Get and set accessor with mismatched type annotations (only g2 is an error after #43662 implemented)
|
||||
var g1 = { get a() { return 4; }, set a(n) { } };
|
||||
var g2 = { get a() { return 4; }, set a(n) { } };
|
||||
var g3 = { get a() { return undefined; }, set a(n) { } };
|
||||
|
||||
@@ -183,7 +183,7 @@ var f17 = { a: 0, get b() { return 1; }, get a() { return 0; } };
|
||||
>b : Symbol(b, Decl(objectLiteralErrors.ts, 38, 17))
|
||||
>a : Symbol(a, Decl(objectLiteralErrors.ts, 38, 40))
|
||||
|
||||
// Get and set accessor with mismatched type annotations
|
||||
// Get and set accessor with mismatched type annotations (only g2 is an error after #43662 implemented)
|
||||
var g1 = { get a(): number { return 4; }, set a(n: string) { } };
|
||||
>g1 : Symbol(g1, Decl(objectLiteralErrors.ts, 41, 3))
|
||||
>a : Symbol(a, Decl(objectLiteralErrors.ts, 41, 10), Decl(objectLiteralErrors.ts, 41, 41))
|
||||
|
||||
@@ -293,7 +293,7 @@ var f17 = { a: 0, get b() { return 1; }, get a() { return 0; } };
|
||||
>a : number
|
||||
>0 : 0
|
||||
|
||||
// Get and set accessor with mismatched type annotations
|
||||
// Get and set accessor with mismatched type annotations (only g2 is an error after #43662 implemented)
|
||||
var g1 = { get a(): number { return 4; }, set a(n: string) { } };
|
||||
>g1 : { a: number; }
|
||||
>{ get a(): number { return 4; }, set a(n: string) { } } : { a: number; }
|
||||
|
||||
@@ -9,7 +9,7 @@ abstract class B implements A {
|
||||
abstract get readonlyProp(): string;
|
||||
abstract m(): string;
|
||||
abstract get mismatch(): string;
|
||||
abstract set mismatch(val: number); // error, not same type
|
||||
abstract set mismatch(val: number);
|
||||
}
|
||||
class C extends B {
|
||||
readonly ro = "readonly please";
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
// @lib: esnext,dom
|
||||
// @declaration: true
|
||||
|
||||
export {};
|
||||
|
||||
interface Element {
|
||||
get style(): CSSStyleDeclaration;
|
||||
set style(cssText: string);
|
||||
}
|
||||
|
||||
declare const element: Element;
|
||||
element.style = "color: red";
|
||||
element.style.animationTimingFunction;
|
||||
element.style = element.style; // error
|
||||
|
||||
// Now that we don't check for getter/setter assignability, we should
|
||||
// ensure the setter annotation is actually checked even if it's never observed.
|
||||
|
||||
type Fail<T extends never> = T;
|
||||
interface I1 {
|
||||
get x(): number;
|
||||
set x(value: Fail<string>);
|
||||
}
|
||||
const o1 = {
|
||||
get x(): number { return 0; },
|
||||
set x(value: Fail<string>) {}
|
||||
}
|
||||
|
||||
// A setter annotation still implies the getter return type.
|
||||
|
||||
const o2 = {
|
||||
get p1() { return 0; }, // error - no annotation means type is implied from the setter annotation
|
||||
set p1(value: string) {},
|
||||
|
||||
get p2(): number { return 0; }, // ok - explicit annotation
|
||||
set p2(value: string) {},
|
||||
};
|
||||
@@ -40,7 +40,7 @@ var f15 = { "100": 0, get 1e2() { return 0; } };
|
||||
var f16 = { 0x20: 0, get 3.2e1() { return 0; } };
|
||||
var f17 = { a: 0, get b() { return 1; }, get a() { return 0; } };
|
||||
|
||||
// Get and set accessor with mismatched type annotations
|
||||
// Get and set accessor with mismatched type annotations (only g2 is an error after #43662 implemented)
|
||||
var g1 = { get a(): number { return 4; }, set a(n: string) { } };
|
||||
var g2 = { get a() { return 4; }, set a(n: string) { } };
|
||||
var g3 = { get a(): number { return undefined; }, set a(n: string) { } };
|
||||
|
||||
@@ -16,4 +16,4 @@
|
||||
verify.quickInfoAt("1", "var b: string");
|
||||
|
||||
// TypeCheck
|
||||
verify.numberOfErrorsInCurrentFile(2);
|
||||
verify.numberOfErrorsInCurrentFile(1);
|
||||
Reference in New Issue
Block a user