File: noImplicitSymbolToString.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 (46 lines) | stat: -rw-r--r-- 805 bytes parent folder | download | duplicates (3)
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
// Fix #19666

let symbol!: symbol;
let str = "hello ";

const templateStr = `hello ${symbol}`;
const appendStr = "hello " + symbol;
str += symbol;

let symbolUnionNumber!: symbol | number;
let symbolUnionString!: symbol | string;

const templateStrUnion = `union with number ${symbolUnionNumber} and union with string ${symbolUnionString}`;


// Fix #44462

type StringOrSymbol = string | symbol;

function getKey<S extends StringOrSymbol>(key: S) {
    return `${key} is the key`;
}

function getKey1<S extends symbol>(key: S) {
    let s1!: S;
    `${s1}`;
    s1 + '';
    +s1;

    let s2!: S | string;
    `${s2}`;
    s2 + '';
    +s2;
}

function getKey2<S extends string>(key: S) {
    let s1!: S;
    `${s1}`;
    s1 + '';
    +s1;

    let s2!: S | symbol;
    `${s2}`;
    s2 + '';
    +s2;
}