File: functionExpressionContextualTyping2.symbols

package info (click to toggle)
node-typescript 4.9.5%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 533,908 kB
  • sloc: javascript: 2,018,330; makefile: 7; sh: 1
file content (25 lines) | stat: -rw-r--r-- 1,625 bytes parent folder | download | duplicates (5)
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
=== tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts ===
// A contextual signature S is extracted from a function type T as follows:
//      If T is a function type with exactly one call signature, and if that call signature is non- generic, S is that signature.
//      If T is a union type, let U be the set of element types in T that have call signatures.
//          If each type in U has exactly one call signature and that call signature is non- generic,
//          and if all of the signatures are identical ignoring return types, then S is a signature
//          with the same parameters and a union of the return types.
//      Otherwise, no contextual signature can be extracted from T and S is undefined.

var a0: (n: number, s: string) => number
>a0 : Symbol(a0, Decl(functionExpressionContextualTyping2.ts, 8, 3))
>n : Symbol(n, Decl(functionExpressionContextualTyping2.ts, 8, 9))
>s : Symbol(s, Decl(functionExpressionContextualTyping2.ts, 8, 19))

var a1: typeof a0 | ((n: number, s: string) => string);
>a1 : Symbol(a1, Decl(functionExpressionContextualTyping2.ts, 9, 3))
>a0 : Symbol(a0, Decl(functionExpressionContextualTyping2.ts, 8, 3))
>n : Symbol(n, Decl(functionExpressionContextualTyping2.ts, 9, 22))
>s : Symbol(s, Decl(functionExpressionContextualTyping2.ts, 9, 32))

a1 = (foo, bar) => { return true; }  // Error
>a1 : Symbol(a1, Decl(functionExpressionContextualTyping2.ts, 9, 3))
>foo : Symbol(foo, Decl(functionExpressionContextualTyping2.ts, 10, 6))
>bar : Symbol(bar, Decl(functionExpressionContextualTyping2.ts, 10, 10))