TypeScript/tests/baselines/reference/interfaceExtendsObjectIntersectionErrors.errors.txt
Anders Hejlsberg 0e905be42b
Index signatures for symbols and template literal strings (#44512)
* Switch index signature storage to 'indexInfos: IndexInfo[]' property

* Accept new baselines

* Remove another usage of IndexKind enum

* Update getIndexedAccessType and resolveMappedTypeMembers

* Accept new baselines

* Update grammar checking for index signatures

* Accept new baselines

* Consider all index signatures in mapped types and union types

* Accept new baselines

* Update getIndexType

* Accept new baselines

* Intersect multiple applicable index signatures

* Use getApplicableIndexInfo instead of hardwired string/number handling

* Update index signature relationship checking

* Report type for which index signature is missing

* Report type for which index signature is missing

* Accept new baselines

* Make 'number' index signatures consistently apply to numeric strings

* Accept new baselines

* Update fourslash test

* Revise index constraint checking

* Accept new baselines

* Update error messages

* Accept new baselines

* Update type inference from index signatures

* Update isKnownProperty

* Update contextual typing based on index signatures

* Accept new baselines

* Support union types in index signature declarations

* Accept new baselines

* Check duplicate index signatures / remove redundant template literals from unions with string

* Accept new baselines

* Include key type in diagnostic / check symbol-named properties

* Accept new baselines

* Minor fix

* Add tests

* Accept new baselines

* Add optimized findApplicableIndexInfoForName

* Accept new baselines

* Another place we don't need to obtain literal type for property name

* Accept new baselines

* Don't create literal types that are going to be discarded

* Individual maps for string, number, bigint, and enum literal types

* Remove ineffective optimizations

* Accept new baselines

* Permit intersections as key types in index signatures

* Index expression in element access is template literal context

* Add tests

* Accept new baselines

* Symbol index signatures from object literals with computed symbol properties

* Accept new baselines

* Add more tests

* Accept new baselines

* Implement Go To Definition for all applicable index signatures

* Add fourslash test

* Accept new API baselines
2021-06-21 11:25:42 -07:00

184 lines
13 KiB
Plaintext

tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(7,11): error TS2430: Interface 'I1' incorrectly extends interface 'T1'.
Types of property 'a' are incompatible.
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(8,11): error TS2430: Interface 'I2' incorrectly extends interface 'T2'.
Type 'I2' is not assignable to type '{ b: number; }'.
Types of property 'b' are incompatible.
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(9,11): error TS2430: Interface 'I3' incorrectly extends interface 'number[]'.
Types of property 'length' are incompatible.
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(10,11): error TS2430: Interface 'I4' incorrectly extends interface '[string, number]'.
Types of property '0' are incompatible.
Type 'number' is not assignable to type 'string'.
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(11,11): error TS2430: Interface 'I5' incorrectly extends interface 'T5'.
Types of property 'c' are incompatible.
Type 'number' is not assignable to type 'string'.
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(16,38): error TS2416: Property 'a' in type 'C1' is not assignable to the same property in base type 'T1'.
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(17,38): error TS2416: Property 'b' in type 'C2' is not assignable to the same property in base type 'T2'.
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(18,38): error TS2416: Property 'length' in type 'C3' is not assignable to the same property in base type 'number[]'.
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(19,38): error TS2416: Property '0' in type 'C4' is not assignable to the same property in base type '[string, number]'.
Type 'number' is not assignable to type 'string'.
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(20,38): error TS2416: Property 'c' in type 'C5' is not assignable to the same property in base type 'T5'.
Type 'number' is not assignable to type 'string'.
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(30,11): error TS2430: Interface 'I10' incorrectly extends interface 'typeof CX'.
Types of property 'a' are incompatible.
Type 'number' is not assignable to type 'string'.
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(31,11): error TS2430: Interface 'I11' incorrectly extends interface 'typeof EX'.
Types of property 'C' are incompatible.
Type 'string' is not assignable to type 'EX'.
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(32,11): error TS2430: Interface 'I12' incorrectly extends interface 'typeof NX'.
Types of property 'a' are incompatible.
Type 'number' is not assignable to type '"hello"'.
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(33,29): error TS2411: Property 'a' of type 'string' is not assignable to 'string' index type 'number'.
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(33,29): error TS2411: Property 'prototype' of type 'CX' is not assignable to 'string' index type 'number'.
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(34,29): error TS2413: 'number' index type 'string' is not assignable to 'string' index type 'number'.
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(35,29): error TS2411: Property 'a' of type '"hello"' is not assignable to 'string' index type 'number'.
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(39,11): error TS2430: Interface 'I20' incorrectly extends interface 'Partial<T1>'.
Types of property 'a' are incompatible.
Type 'string' is not assignable to type 'number | undefined'.
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(40,11): error TS2430: Interface 'I21' incorrectly extends interface 'Readonly<T1>'.
Types of property 'a' are incompatible.
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(41,11): error TS2430: Interface 'I22' incorrectly extends interface 'Identifiable<T1>'.
Type 'I22' is not assignable to type 'T1'.
Types of property 'a' are incompatible.
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(42,11): error TS2430: Interface 'I23' incorrectly extends interface 'Identifiable<T1 & { b: number; }>'.
Type 'I23' is not assignable to type 'T1'.
Types of property 'a' are incompatible.
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(46,23): error TS2312: An interface can only extend an object type or intersection of object types with statically known members.
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(47,26): error TS2312: An interface can only extend an object type or intersection of object types with statically known members.
==== tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts (23 errors) ====
type T1 = { a: number };
type T2 = T1 & { b: number };
type T3 = number[];
type T4 = [string, number];
type T5 = { [P in 'a' | 'b' | 'c']: string };
interface I1 extends T1 { a: string }
~~
!!! error TS2430: Interface 'I1' incorrectly extends interface 'T1'.
!!! error TS2430: Types of property 'a' are incompatible.
!!! error TS2430: Type 'string' is not assignable to type 'number'.
interface I2 extends T2 { b: string }
~~
!!! error TS2430: Interface 'I2' incorrectly extends interface 'T2'.
!!! error TS2430: Type 'I2' is not assignable to type '{ b: number; }'.
!!! error TS2430: Types of property 'b' are incompatible.
!!! error TS2430: Type 'string' is not assignable to type 'number'.
interface I3 extends T3 { length: string }
~~
!!! error TS2430: Interface 'I3' incorrectly extends interface 'number[]'.
!!! error TS2430: Types of property 'length' are incompatible.
!!! error TS2430: Type 'string' is not assignable to type 'number'.
interface I4 extends T4 { 0: number }
~~
!!! error TS2430: Interface 'I4' incorrectly extends interface '[string, number]'.
!!! error TS2430: Types of property '0' are incompatible.
!!! error TS2430: Type 'number' is not assignable to type 'string'.
interface I5 extends T5 { c: number }
~~
!!! error TS2430: Interface 'I5' incorrectly extends interface 'T5'.
!!! error TS2430: Types of property 'c' are incompatible.
!!! error TS2430: Type 'number' is not assignable to type 'string'.
type Constructor<T> = new () => T;
declare function Constructor<T>(): Constructor<T>;
class C1 extends Constructor<T1>() { a: string }
~
!!! error TS2416: Property 'a' in type 'C1' is not assignable to the same property in base type 'T1'.
!!! error TS2416: Type 'string' is not assignable to type 'number'.
class C2 extends Constructor<T2>() { b: string }
~
!!! error TS2416: Property 'b' in type 'C2' is not assignable to the same property in base type 'T2'.
!!! error TS2416: Type 'string' is not assignable to type 'number'.
class C3 extends Constructor<T3>() { length: string }
~~~~~~
!!! error TS2416: Property 'length' in type 'C3' is not assignable to the same property in base type 'number[]'.
!!! error TS2416: Type 'string' is not assignable to type 'number'.
class C4 extends Constructor<T4>() { 0: number }
~
!!! error TS2416: Property '0' in type 'C4' is not assignable to the same property in base type '[string, number]'.
!!! error TS2416: Type 'number' is not assignable to type 'string'.
class C5 extends Constructor<T5>() { c: number }
~
!!! error TS2416: Property 'c' in type 'C5' is not assignable to the same property in base type 'T5'.
!!! error TS2416: Type 'number' is not assignable to type 'string'.
declare class CX { static a: string }
declare enum EX { A, B, C }
declare namespace NX { export const a = "hello" }
type TCX = typeof CX;
type TEX = typeof EX;
type TNX = typeof NX;
interface I10 extends TCX { a: number }
~~~
!!! error TS2430: Interface 'I10' incorrectly extends interface 'typeof CX'.
!!! error TS2430: Types of property 'a' are incompatible.
!!! error TS2430: Type 'number' is not assignable to type 'string'.
interface I11 extends TEX { C: string }
~~~
!!! error TS2430: Interface 'I11' incorrectly extends interface 'typeof EX'.
!!! error TS2430: Types of property 'C' are incompatible.
!!! error TS2430: Type 'string' is not assignable to type 'EX'.
interface I12 extends TNX { a: number }
~~~
!!! error TS2430: Interface 'I12' incorrectly extends interface 'typeof NX'.
!!! error TS2430: Types of property 'a' are incompatible.
!!! error TS2430: Type 'number' is not assignable to type '"hello"'.
interface I14 extends TCX { [x: string]: number }
~~~~~~~~~~~~~~~~~~~
!!! error TS2411: Property 'a' of type 'string' is not assignable to 'string' index type 'number'.
~~~~~~~~~~~~~~~~~~~
!!! error TS2411: Property 'prototype' of type 'CX' is not assignable to 'string' index type 'number'.
interface I15 extends TEX { [x: string]: number }
~~~~~~~~~~~~~~~~~~~
!!! error TS2413: 'number' index type 'string' is not assignable to 'string' index type 'number'.
interface I16 extends TNX { [x: string]: number }
~~~~~~~~~~~~~~~~~~~
!!! error TS2411: Property 'a' of type '"hello"' is not assignable to 'string' index type 'number'.
type Identifiable<T> = { _id: string } & T;
interface I20 extends Partial<T1> { a: string }
~~~
!!! error TS2430: Interface 'I20' incorrectly extends interface 'Partial<T1>'.
!!! error TS2430: Types of property 'a' are incompatible.
!!! error TS2430: Type 'string' is not assignable to type 'number | undefined'.
interface I21 extends Readonly<T1> { a: string }
~~~
!!! error TS2430: Interface 'I21' incorrectly extends interface 'Readonly<T1>'.
!!! error TS2430: Types of property 'a' are incompatible.
!!! error TS2430: Type 'string' is not assignable to type 'number'.
interface I22 extends Identifiable<T1> { a: string }
~~~
!!! error TS2430: Interface 'I22' incorrectly extends interface 'Identifiable<T1>'.
!!! error TS2430: Type 'I22' is not assignable to type 'T1'.
!!! error TS2430: Types of property 'a' are incompatible.
!!! error TS2430: Type 'string' is not assignable to type 'number'.
interface I23 extends Identifiable<T1 & { b: number}> { a: string }
~~~
!!! error TS2430: Interface 'I23' incorrectly extends interface 'Identifiable<T1 & { b: number; }>'.
!!! error TS2430: Type 'I23' is not assignable to type 'T1'.
!!! error TS2430: Types of property 'a' are incompatible.
!!! error TS2430: Type 'string' is not assignable to type 'number'.
type U = { a: number } | { b: string };
interface I30 extends U { x: string }
~
!!! error TS2312: An interface can only extend an object type or intersection of object types with statically known members.
interface I31<T> extends T { x: string }
~
!!! error TS2312: An interface can only extend an object type or intersection of object types with statically known members.