TypeScript/tests/baselines/reference/typeGuardsOnClassProperty.types
Wesley Wigham 78a99241d8
Reuse input type nodes when serializing signature parameter and return types (#37444)
* Accept change

* Accept the huge set of ever so slightly changed baselines

* Update return type logic to only reuse nodes if original nodes share scope with current node, like property types, only reuse nodes if symbols referened are acessible, reuse nodes for property signatures, too

* Only reuse nodes when a context is provided (otherwise identifier printback may fail)

* Only track symbol if symbol is found and no error is recorded

* Fix type parameter reuse lookup

* Forbid cjs module.exports references in retained nodes

* Adjust check for cjs export references to not include bad module type in output

* Add symbol to all identifiers we see in existing nodes for quickinfo

* Accept fourslash baseline updates

* Accept slightly updated baseline post-merge

* Do not copy original nodes for error types, replace empty type references with any
2020-04-01 19:50:21 -07:00

113 lines
3.4 KiB
Plaintext

=== tests/cases/conformance/expressions/typeGuards/typeGuardsOnClassProperty.ts ===
// Note that type guards affect types of variables and parameters only and
// have no effect on members of objects such as properties.
// Note that the class's property must be copied to a local variable for
// the type guard to have an effect
class D {
>D : D
data: string | string[];
>data : string | string[]
getData() {
>getData : () => string
var data = this.data;
>data : string | string[]
>this.data : string | string[]
>this : this
>data : string | string[]
return typeof data === "string" ? data : data.join(" ");
>typeof data === "string" ? data : data.join(" ") : string
>typeof data === "string" : boolean
>typeof data : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>data : string | string[]
>"string" : "string"
>data : string
>data.join(" ") : string
>data.join : (separator?: string) => string
>data : string[]
>join : (separator?: string) => string
>" " : " "
}
getData1() {
>getData1 : () => string
return typeof this.data === "string" ? this.data : this.data.join(" ");
>typeof this.data === "string" ? this.data : this.data.join(" ") : string
>typeof this.data === "string" : boolean
>typeof this.data : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>this.data : string | string[]
>this : this
>data : string | string[]
>"string" : "string"
>this.data : string
>this : this
>data : string
>this.data.join(" ") : string
>this.data.join : (separator?: string) => string
>this.data : string[]
>this : this
>data : string[]
>join : (separator?: string) => string
>" " : " "
}
}
var o: {
>o : { prop1: number | string; prop2: boolean | string; }
prop1: number|string;
>prop1 : string | number
prop2: boolean|string;
>prop2 : string | boolean
} = {
>{ prop1: "string" , prop2: true } : { prop1: string; prop2: true; }
prop1: "string" ,
>prop1 : string
>"string" : "string"
prop2: true
>prop2 : true
>true : true
}
if (typeof o.prop1 === "string" && o.prop1.toLowerCase()) {}
>typeof o.prop1 === "string" && o.prop1.toLowerCase() : string
>typeof o.prop1 === "string" : boolean
>typeof o.prop1 : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>o.prop1 : string | number
>o : { prop1: string | number; prop2: string | boolean; }
>prop1 : string | number
>"string" : "string"
>o.prop1.toLowerCase() : string
>o.prop1.toLowerCase : () => string
>o.prop1 : string
>o : { prop1: string | number; prop2: string | boolean; }
>prop1 : string
>toLowerCase : () => string
var prop1 = o.prop1;
>prop1 : string | number
>o.prop1 : string | number
>o : { prop1: string | number; prop2: string | boolean; }
>prop1 : string | number
if (typeof prop1 === "string" && prop1.toLocaleLowerCase()) { }
>typeof prop1 === "string" && prop1.toLocaleLowerCase() : string
>typeof prop1 === "string" : boolean
>typeof prop1 : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>prop1 : string | number
>"string" : "string"
>prop1.toLocaleLowerCase() : string
>prop1.toLocaleLowerCase : (locales?: string | string[]) => string
>prop1 : string
>toLocaleLowerCase : (locales?: string | string[]) => string