File: narrowingConstrainedTypeParameter.types

package info (click to toggle)
node-typescript 2.1.5-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 203,952 kB
  • ctags: 52,987
  • sloc: sh: 11; makefile: 5
file content (52 lines) | stat: -rw-r--r-- 1,167 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
=== tests/cases/compiler/narrowingConstrainedTypeParameter.ts ===

// Repro from #10811

interface Pet {
>Pet : Pet

    name: string;
>name : string
}

function isPet(pet: any): pet is Pet {
>isPet : (pet: any) => pet is Pet
>pet : any
>pet : any
>Pet : Pet

    return typeof pet.name === "string";
>typeof pet.name === "string" : boolean
>typeof pet.name : string
>pet.name : any
>pet : any
>name : any
>"string" : "string"
}

export function speak<TPet extends Pet>(pet: TPet, voice: (pet: TPet) => string): string {
>speak : <TPet extends Pet>(pet: TPet, voice: (pet: TPet) => string) => string
>TPet : TPet
>Pet : Pet
>pet : TPet
>TPet : TPet
>voice : (pet: TPet) => string
>pet : TPet
>TPet : TPet

    if (!isPet(pet)) {
>!isPet(pet) : boolean
>isPet(pet) : boolean
>isPet : (pet: any) => pet is Pet
>pet : TPet

        throw new Error("Expected \"pet\" to be a Pet");
>new Error("Expected \"pet\" to be a Pet") : Error
>Error : ErrorConstructor
>"Expected \"pet\" to be a Pet" : "Expected \"pet\" to be a Pet"
    }
    return voice(pet);
>voice(pet) : string
>voice : (pet: TPet) => string
>pet : TPet
}