File: freshLiteralInference.ts

package info (click to toggle)
node-typescript 4.9.5%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 533,908 kB
  • sloc: javascript: 2,018,330; makefile: 7; sh: 1
file content (14 lines) | stat: -rw-r--r-- 497 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
declare function f1<T extends "1" | "2" | "3">(x: T): T;

const value = f1("1");  // regular "1"
let x1 = value;  // regular "1"

declare function f2<T extends "1" | "2" | "3">(x: { value: T }): { value: T };

const obj2 = f2({ value: "1" });  // { value: regular "1" }
let x2 = obj2.value;  // regular "1"

declare function f3<T extends { value: "1" | "2" | "3" }>(obj: T): T;

const obj3 = f3({ value: "1" });  // before: { value: fresh "1" }
let x3 = obj3.value;  // before: string, after: "1"