mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 21:53:42 -06:00
Truncate long types in error messages
This commit is contained in:
parent
18c1789aa4
commit
9f3d83adeb
@ -943,20 +943,36 @@ module ts {
|
||||
writer.write(symbolToString(symbol, enclosingDeclaration, meaning));
|
||||
}
|
||||
|
||||
function createSingleLineTextWriter() {
|
||||
function createSingleLineTextWriter(maxLength?: number) {
|
||||
var result = "";
|
||||
var overflow = false;
|
||||
function write(s: string) {
|
||||
if (!overflow) {
|
||||
result += s;
|
||||
if (result.length > maxLength) {
|
||||
result = result.substr(0, maxLength - 3) + "...";
|
||||
overflow = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
write(s: string) { result += s; },
|
||||
writeSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags) { writeSymbolToTextWriter(symbol, enclosingDeclaration, meaning, this); },
|
||||
writeLine() { result += " "; },
|
||||
write: write,
|
||||
writeSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags) {
|
||||
writeSymbolToTextWriter(symbol, enclosingDeclaration, meaning, this);
|
||||
},
|
||||
writeLine() {
|
||||
write(" ");
|
||||
},
|
||||
increaseIndent() { },
|
||||
decreaseIndent() { },
|
||||
getText() { return result; }
|
||||
getText() {
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string {
|
||||
var stringWriter = createSingleLineTextWriter();
|
||||
var stringWriter = createSingleLineTextWriter(flags & TypeFormatFlags.NoTruncation ? undefined : 100);
|
||||
// TODO(shkamat): typeToString should take enclosingDeclaration as input, once we have implemented enclosingDeclaration
|
||||
writeTypeToTextWriter(type, enclosingDeclaration, flags, stringWriter);
|
||||
return stringWriter.getText();
|
||||
|
||||
@ -631,12 +631,10 @@ module ts {
|
||||
}
|
||||
|
||||
export enum TypeFormatFlags {
|
||||
None = 0x00000000,
|
||||
|
||||
/** writes Array<T> instead T[] */
|
||||
WriteArrayAsGenericType = 0x00000001, // Declarations
|
||||
|
||||
UseTypeOfFunction = 0x00000002, // instead of writing signature type of function use typeof
|
||||
None = 0x00000000,
|
||||
WriteArrayAsGenericType = 0x00000001, // Write Array<T> instead T[]
|
||||
UseTypeOfFunction = 0x00000002, // Write typeof instead of function type literal
|
||||
NoTruncation = 0x00000004, // Don't truncate typeToString result
|
||||
}
|
||||
|
||||
export enum SymbolAccessibility {
|
||||
|
||||
@ -86,7 +86,7 @@ class TypeWriterWalker {
|
||||
column: lineAndCharacter.character,
|
||||
syntaxKind: ts.SyntaxKind[node.kind],
|
||||
sourceText: sourceText,
|
||||
type: this.checker.typeToString(type, node.parent, ts.TypeFormatFlags.None)
|
||||
type: this.checker.typeToString(type, node.parent, ts.TypeFormatFlags.NoTruncation)
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
~
|
||||
!!! Expression expected.
|
||||
~~~
|
||||
!!! Type 'number' is not assignable to type '{ (arrayLength?: number): any[]; <T>(arrayLength: number): T[]; <T>(...items: T[]): T[]; new (arrayLength?: number): any[]; new <T>(arrayLength: number): T[]; new <T>(...items: T[]): T[]; isArray(arg: any): boolean; prototype: any[]; }':
|
||||
!!! Type 'number' is not assignable to type '{ (arrayLength?: number): any[]; <T>(arrayLength: number): T[]; <T>(...items: T[]): T[]; new (arr...':
|
||||
!!! Property 'isArray' is missing in type 'Number'.
|
||||
var xs4: typeof Array<typeof x>;
|
||||
~
|
||||
@ -18,4 +18,4 @@
|
||||
~
|
||||
!!! Expression expected.
|
||||
~~~
|
||||
!!! Type 'number' is not assignable to type '{ (arrayLength?: number): any[]; <T>(arrayLength: number): T[]; <T>(...items: T[]): T[]; new (arrayLength?: number): any[]; new <T>(arrayLength: number): T[]; new <T>(...items: T[]): T[]; isArray(arg: any): boolean; prototype: any[]; }'.
|
||||
!!! Type 'number' is not assignable to type '{ (arrayLength?: number): any[]; <T>(arrayLength: number): T[]; <T>(...items: T[]): T[]; new (arr...'.
|
||||
@ -52,7 +52,7 @@
|
||||
var b8: <T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U;
|
||||
a8 = b8; // error, { foo: number } and Base are incompatible
|
||||
~~
|
||||
!!! Type '<T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U' is not assignable to type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived':
|
||||
!!! Type '<T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T)...' is not assignable to type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived':
|
||||
!!! Types of parameters 'y' and 'y' are incompatible:
|
||||
!!! Type '(arg2: { foo: number; }) => any' is not assignable to type '(arg2: Base) => Derived':
|
||||
!!! Types of parameters 'arg2' and 'arg2' are incompatible:
|
||||
@ -61,7 +61,7 @@
|
||||
!!! Type 'number' is not assignable to type 'string'.
|
||||
b8 = a8; // error, { foo: number } and Base are incompatible
|
||||
~~
|
||||
!!! Type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type '<T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U':
|
||||
!!! Type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type '<T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T)...':
|
||||
!!! Types of parameters 'y' and 'y' are incompatible:
|
||||
!!! Type '(arg2: Base) => Derived' is not assignable to type '(arg2: { foo: number; }) => any':
|
||||
!!! Types of parameters 'arg2' and 'arg2' are incompatible:
|
||||
|
||||
@ -52,7 +52,7 @@
|
||||
var b8: new <T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U;
|
||||
a8 = b8; // error, type mismatch
|
||||
~~
|
||||
!!! Type 'new <T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U' is not assignable to type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived':
|
||||
!!! Type 'new <T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r...' is not assignable to type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived':
|
||||
!!! Types of parameters 'y' and 'y' are incompatible:
|
||||
!!! Type '(arg2: { foo: number; }) => any' is not assignable to type '(arg2: Base) => Derived':
|
||||
!!! Types of parameters 'arg2' and 'arg2' are incompatible:
|
||||
@ -61,7 +61,7 @@
|
||||
!!! Type 'number' is not assignable to type 'string'.
|
||||
b8 = a8; // error
|
||||
~~
|
||||
!!! Type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type 'new <T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U':
|
||||
!!! Type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type 'new <T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r...':
|
||||
!!! Types of parameters 'y' and 'y' are incompatible:
|
||||
!!! Type '(arg2: Base) => Derived' is not assignable to type '(arg2: { foo: number; }) => any':
|
||||
!!! Types of parameters 'arg2' and 'arg2' are incompatible:
|
||||
@ -93,24 +93,24 @@
|
||||
var b16: new <T>(x: (a: T) => T) => T[];
|
||||
a16 = b16; // error
|
||||
~~~
|
||||
!!! Type 'new <T>(x: (a: T) => T) => T[]' is not assignable to type '{ new (x: { new (a: number): number; new (a?: number): number; }): number[]; new (x: { new (a: boolean): boolean; new (a?: boolean): boolean; }): boolean[]; }':
|
||||
!!! Type 'new <T>(x: (a: T) => T) => T[]' is not assignable to type '{ new (x: { new (a: number): number; new (a?: number): number; }): number[]; new (x: { new (a: bo...':
|
||||
!!! Types of parameters 'x' and 'x' are incompatible:
|
||||
!!! Type '(a: any) => any' is not assignable to type '{ new (a: number): number; new (a?: number): number; }'.
|
||||
b16 = a16; // error
|
||||
~~~
|
||||
!!! Type '{ new (x: { new (a: number): number; new (a?: number): number; }): number[]; new (x: { new (a: boolean): boolean; new (a?: boolean): boolean; }): boolean[]; }' is not assignable to type 'new <T>(x: (a: T) => T) => T[]':
|
||||
!!! Type '{ new (x: { new (a: number): number; new (a?: number): number; }): number[]; new (x: { new (a: bo...' is not assignable to type 'new <T>(x: (a: T) => T) => T[]':
|
||||
!!! Types of parameters 'x' and 'x' are incompatible:
|
||||
!!! Type '{ new (a: number): number; new (a?: number): number; }' is not assignable to type '(a: any) => any'.
|
||||
|
||||
var b17: new <T>(x: (a: T) => T) => any[];
|
||||
a17 = b17; // error
|
||||
~~~
|
||||
!!! Type 'new <T>(x: (a: T) => T) => any[]' is not assignable to type '{ new (x: { new <T extends Derived>(a: T): T; new <T extends Base>(a: T): T; }): any[]; new (x: { new <T extends Derived2>(a: T): T; new <T extends Base>(a: T): T; }): any[]; }':
|
||||
!!! Type 'new <T>(x: (a: T) => T) => any[]' is not assignable to type '{ new (x: { new <T extends Derived>(a: T): T; new <T extends Base>(a: T): T; }): any[]; new (x: {...':
|
||||
!!! Types of parameters 'x' and 'x' are incompatible:
|
||||
!!! Type '(a: any) => any' is not assignable to type '{ new <T extends Derived>(a: T): T; new <T extends Base>(a: T): T; }'.
|
||||
b17 = a17; // error
|
||||
~~~
|
||||
!!! Type '{ new (x: { new <T extends Derived>(a: T): T; new <T extends Base>(a: T): T; }): any[]; new (x: { new <T extends Derived2>(a: T): T; new <T extends Base>(a: T): T; }): any[]; }' is not assignable to type 'new <T>(x: (a: T) => T) => any[]':
|
||||
!!! Type '{ new (x: { new <T extends Derived>(a: T): T; new <T extends Base>(a: T): T; }): any[]; new (x: {...' is not assignable to type 'new <T>(x: (a: T) => T) => any[]':
|
||||
!!! Types of parameters 'x' and 'x' are incompatible:
|
||||
!!! Type '{ new <T extends Derived>(a: T): T; new <T extends Base>(a: T): T; }' is not assignable to type '(a: any) => any'.
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@
|
||||
~~
|
||||
!!! Interface 'I4' incorrectly extends interface 'A':
|
||||
!!! Types of property 'a8' are incompatible:
|
||||
!!! Type '<T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U' is not assignable to type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived':
|
||||
!!! Type '<T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T)...' is not assignable to type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived':
|
||||
!!! Types of parameters 'y' and 'y' are incompatible:
|
||||
!!! Type '(arg2: { foo: number; }) => any' is not assignable to type '(arg2: Base) => Derived':
|
||||
!!! Types of parameters 'arg2' and 'arg2' are incompatible:
|
||||
|
||||
@ -58,7 +58,7 @@
|
||||
~~
|
||||
!!! Interface 'I4' incorrectly extends interface 'A':
|
||||
!!! Types of property 'a8' are incompatible:
|
||||
!!! Type 'new <T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U' is not assignable to type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived':
|
||||
!!! Type 'new <T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r...' is not assignable to type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived':
|
||||
!!! Types of parameters 'y' and 'y' are incompatible:
|
||||
!!! Type '(arg2: { foo: number; }) => any' is not assignable to type '(arg2: Base) => Derived':
|
||||
!!! Types of parameters 'arg2' and 'arg2' are incompatible:
|
||||
|
||||
@ -8,4 +8,4 @@
|
||||
!!! Property 'getOwnPropertyNamess' does not exist on type '{ a: string; b: number; }'.
|
||||
Object.getOwnPropertyNamess(null);
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
!!! Property 'getOwnPropertyNamess' does not exist on type '{ (): any; (value: any): any; new (value?: any): Object; prototype: Object; getPrototypeOf(o: any): any; getOwnPropertyDescriptor(o: any, p: string): PropertyDescriptor; getOwnPropertyNames(o: any): string[]; create(o: any, properties?: PropertyDescriptorMap): any; defineProperty(o: any, p: string, attributes: PropertyDescriptor): any; defineProperties(o: any, properties: PropertyDescriptorMap): any; seal(o: any): any; freeze(o: any): any; preventExtensions(o: any): any; isSealed(o: any): boolean; isFrozen(o: any): boolean; isExtensible(o: any): boolean; keys(o: any): string[]; }'.
|
||||
!!! Property 'getOwnPropertyNamess' does not exist on type '{ (): any; (value: any): any; new (value?: any): Object; prototype: Object; getPrototypeOf(o: any...'.
|
||||
@ -98,7 +98,7 @@
|
||||
// error
|
||||
var b: { [x: number]: string; } = {
|
||||
~
|
||||
!!! Type '{ [x: number]: {}; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: unknown; X: string; foo: () => string; }' is not assignable to type '{ [x: number]: string; }':
|
||||
!!! Type '{ [x: number]: {}; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e...' is not assignable to type '{ [x: number]: string; }':
|
||||
!!! Index signatures are incompatible:
|
||||
!!! Type '{}' is not assignable to type 'string'.
|
||||
a: '',
|
||||
|
||||
@ -41,7 +41,7 @@
|
||||
// Dotted property access of property that doesn't exist on value's apparent type
|
||||
var cc = obj.qqq; // error
|
||||
~~~
|
||||
!!! Property 'qqq' does not exist on type '{ 10: string; x: string; y: number; z: { n: string; m: number; o: () => boolean; }; 'literal property': number; }'.
|
||||
!!! Property 'qqq' does not exist on type '{ 10: string; x: string; y: number; z: { n: string; m: number; o: () => boolean; }; 'literal prop...'.
|
||||
|
||||
// Bracket notation property access using string literal value on type with property of that literal name
|
||||
var dd = obj['literal property'];
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
==== tests/cases/compiler/redefineArray.ts (1 errors) ====
|
||||
Array = function (n:number, s:string) {return n;};
|
||||
~~~~~
|
||||
!!! Type '(n: number, s: string) => number' is not assignable to type '{ (arrayLength?: number): any[]; <T>(arrayLength: number): T[]; <T>(...items: T[]): T[]; new (arrayLength?: number): any[]; new <T>(arrayLength: number): T[]; new <T>(...items: T[]): T[]; isArray(arg: any): boolean; prototype: any[]; }':
|
||||
!!! Type '(n: number, s: string) => number' is not assignable to type '{ (arrayLength?: number): any[]; <T>(arrayLength: number): T[]; <T>(...items: T[]): T[]; new (arr...':
|
||||
!!! Property 'isArray' is missing in type '(n: number, s: string) => number'.
|
||||
@ -128,7 +128,7 @@
|
||||
// error
|
||||
var b: { [x: string]: string; } = {
|
||||
~
|
||||
!!! Type '{ [x: string]: {}; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: MyString; X: string; foo: () => string; }' is not assignable to type '{ [x: string]: string; }':
|
||||
!!! Type '{ [x: string]: {}; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e...' is not assignable to type '{ [x: string]: string; }':
|
||||
!!! Index signatures are incompatible:
|
||||
!!! Type '{}' is not assignable to type 'string'.
|
||||
a: '',
|
||||
|
||||
@ -24,7 +24,7 @@
|
||||
!!! Property 'x' is missing in type 'Number'.
|
||||
var x5:{ (s:string):number;(n:number):string;x;y;z:number;f(n:number):string;f(s:string):number; }=3;
|
||||
~~
|
||||
!!! Type 'number' is not assignable to type '{ (s: string): number; (n: number): string; x: any; y: any; z: number; f(n: number): string; f(s: string): number; }':
|
||||
!!! Type 'number' is not assignable to type '{ (s: string): number; (n: number): string; x: any; y: any; z: number; f(n: number): string; f(s:...':
|
||||
!!! Property 'x' is missing in type 'Number'.
|
||||
var x6:{ z:number;f:{(n:number):string;(s:string):number;}; }=3;
|
||||
~~
|
||||
@ -53,7 +53,7 @@
|
||||
!!! Property 'length' is missing in type 'Number'.
|
||||
var x12:{z:I;x:boolean;y:(s:string)=>boolean;w:{ z:I;[s:string]:{ x; y; };[n:number]:{x; y;};():boolean; };}[][]=3;
|
||||
~~~
|
||||
!!! Type 'number' is not assignable to type '{ z: I; x: boolean; y: (s: string) => boolean; w: { (): boolean; [x: string]: { x: any; y: any; }; [x: number]: { x: any; y: any; }; z: I; }; }[][]':
|
||||
!!! Type 'number' is not assignable to type '{ z: I; x: boolean; y: (s: string) => boolean; w: { (): boolean; [x: string]: { x: any; y: any; }...':
|
||||
!!! Property 'length' is missing in type 'Number'.
|
||||
var x13:{ new(): number; new(n:number):number; x: string; w: {y: number;}; (): {}; } = 3;
|
||||
~~~
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user