Switch checkObjectLiteral to iterate over element declarations

This commit is contained in:
Jason Freeman
2015-01-19 16:36:32 -08:00
parent 15187e5e1d
commit d192fea774
4 changed files with 55 additions and 63 deletions
@@ -1,8 +1,8 @@
tests/cases/compiler/lastPropertyInLiteralWins.ts(8,5): error TS2300: Duplicate identifier 'thunk'.
tests/cases/compiler/lastPropertyInLiteralWins.ts(9,5): error TS2300: Duplicate identifier 'thunk'.
tests/cases/compiler/lastPropertyInLiteralWins.ts(12,6): error TS2345: Argument of type '{ thunk: (num: number) => void; }' is not assignable to parameter of type 'Thing'.
tests/cases/compiler/lastPropertyInLiteralWins.ts(7,6): error TS2345: Argument of type '{ thunk: (num: number) => void; }' is not assignable to parameter of type 'Thing'.
Types of property 'thunk' are incompatible.
Type '(num: number) => void' is not assignable to type '(str: string) => void'.
tests/cases/compiler/lastPropertyInLiteralWins.ts(8,5): error TS2300: Duplicate identifier 'thunk'.
tests/cases/compiler/lastPropertyInLiteralWins.ts(9,5): error TS2300: Duplicate identifier 'thunk'.
tests/cases/compiler/lastPropertyInLiteralWins.ts(13,5): error TS2300: Duplicate identifier 'thunk'.
tests/cases/compiler/lastPropertyInLiteralWins.ts(14,5): error TS2300: Duplicate identifier 'thunk'.
@@ -15,21 +15,12 @@ tests/cases/compiler/lastPropertyInLiteralWins.ts(14,5): error TS2300: Duplicate
thing.thunk("str");
}
test({ // Should error, as last one wins, and is wrong type
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
thunk: (str: string) => {},
~~~~~
!!! error TS2300: Duplicate identifier 'thunk'.
thunk: (num: number) => {}
~~~~~
!!! error TS2300: Duplicate identifier 'thunk'.
});
test({ // Should be OK. Last 'thunk' is of correct type
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
thunk: (num: number) => {},
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~
!!! error TS2300: Duplicate identifier 'thunk'.
thunk: (str: string) => {}
thunk: (num: number) => {}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~
!!! error TS2300: Duplicate identifier 'thunk'.
@@ -38,4 +29,13 @@ tests/cases/compiler/lastPropertyInLiteralWins.ts(14,5): error TS2300: Duplicate
!!! error TS2345: Argument of type '{ thunk: (num: number) => void; }' is not assignable to parameter of type 'Thing'.
!!! error TS2345: Types of property 'thunk' are incompatible.
!!! error TS2345: Type '(num: number) => void' is not assignable to type '(str: string) => void'.
test({ // Should be OK. Last 'thunk' is of correct type
thunk: (num: number) => {},
~~~~~
!!! error TS2300: Duplicate identifier 'thunk'.
thunk: (str: string) => {}
~~~~~
!!! error TS2300: Duplicate identifier 'thunk'.
});
@@ -1,9 +1,8 @@
tests/cases/compiler/memberOverride.ts(4,5): error TS2300: Duplicate identifier 'a'.
tests/cases/compiler/memberOverride.ts(5,5): error TS2300: Duplicate identifier 'a'.
tests/cases/compiler/memberOverride.ts(8,5): error TS2322: Type 'string' is not assignable to type 'number'.
==== tests/cases/compiler/memberOverride.ts (3 errors) ====
==== tests/cases/compiler/memberOverride.ts (2 errors) ====
// An object initialiser accepts the first definition for the same property with a different type signature
// Should compile, since the second declaration of a overrides the first
var x = {
@@ -15,6 +14,4 @@ tests/cases/compiler/memberOverride.ts(8,5): error TS2322: Type 'string' is not
!!! error TS2300: Duplicate identifier 'a'.
}
var n: number = x.a;
~
!!! error TS2322: Type 'string' is not assignable to type 'number'.
var n: number = x.a;
@@ -11,9 +11,10 @@ tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralType
tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures2.ts(26,5): error TS2300: Duplicate identifier 'foo'.
tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures2.ts(26,5): error TS2381: A signature with an implementation cannot use a string literal type.
tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures2.ts(27,5): error TS2300: Duplicate identifier 'foo'.
tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures2.ts(27,5): error TS2381: A signature with an implementation cannot use a string literal type.
==== tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures2.ts (13 errors) ====
==== tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralTypesInImplementationSignatures2.ts (14 errors) ====
// String literal types are only valid in overload signatures
function foo(x: any);
@@ -67,5 +68,7 @@ tests/cases/conformance/types/objectTypeLiteral/callSignatures/stringLiteralType
foo(x: 'a') { },
~~~
!!! error TS2300: Duplicate identifier 'foo'.
~~~~~~~~~~~~~~~
!!! error TS2381: A signature with an implementation cannot use a string literal type.
}