Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
a.d.ts(7,20): error TS1254: A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.
a.d.ts(8,20): error TS1254: A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.
a.d.ts(9,20): error TS1254: A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.
a.d.ts(13,26): error TS1254: A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.


==== a.d.ts (4 errors) ====
declare enum E { A = 1, B = "b" }
declare namespace NS { const v: 1; }
declare const obj: { readonly x: 1 };

declare const e1 = E.A;
declare const e2 = E["B"];
declare const n1 = NS.v;
~~~~
!!! error TS1254: A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.
declare const n2 = NS["v"];
~~~~~~~
!!! error TS1254: A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.
declare const o1 = obj.x;
~~~~~
!!! error TS1254: A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.

declare class C {
static readonly r1 = E.A;
static readonly r2 = NS.v;
~~~~
!!! error TS1254: A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//// [tests/cases/compiler/ambientConstInitializerNonEnumReference.ts] ////

=== a.d.ts ===
declare enum E { A = 1, B = "b" }
>E : Symbol(E, Decl(a.d.ts, 0, 0))
>A : Symbol(E.A, Decl(a.d.ts, 0, 16))
>B : Symbol(E.B, Decl(a.d.ts, 0, 23))

declare namespace NS { const v: 1; }
>NS : Symbol(NS, Decl(a.d.ts, 0, 33))
>v : Symbol(v, Decl(a.d.ts, 1, 28))

declare const obj: { readonly x: 1 };
>obj : Symbol(obj, Decl(a.d.ts, 2, 13))
>x : Symbol(x, Decl(a.d.ts, 2, 20))

declare const e1 = E.A;
>e1 : Symbol(e1, Decl(a.d.ts, 4, 13))
>E.A : Symbol(E.A, Decl(a.d.ts, 0, 16))
>E : Symbol(E, Decl(a.d.ts, 0, 0))
>A : Symbol(E.A, Decl(a.d.ts, 0, 16))

declare const e2 = E["B"];
>e2 : Symbol(e2, Decl(a.d.ts, 5, 13))
>E : Symbol(E, Decl(a.d.ts, 0, 0))
>"B" : Symbol(E.B, Decl(a.d.ts, 0, 23))

declare const n1 = NS.v;
>n1 : Symbol(n1, Decl(a.d.ts, 6, 13))
>NS.v : Symbol(NS.v, Decl(a.d.ts, 1, 28))
>NS : Symbol(NS, Decl(a.d.ts, 0, 33))
>v : Symbol(NS.v, Decl(a.d.ts, 1, 28))

declare const n2 = NS["v"];
>n2 : Symbol(n2, Decl(a.d.ts, 7, 13))
>NS : Symbol(NS, Decl(a.d.ts, 0, 33))
>"v" : Symbol(NS.v, Decl(a.d.ts, 1, 28))

declare const o1 = obj.x;
>o1 : Symbol(o1, Decl(a.d.ts, 8, 13))
>obj.x : Symbol(x, Decl(a.d.ts, 2, 20))
>obj : Symbol(obj, Decl(a.d.ts, 2, 13))
>x : Symbol(x, Decl(a.d.ts, 2, 20))

declare class C {
>C : Symbol(C, Decl(a.d.ts, 8, 25))

static readonly r1 = E.A;
>r1 : Symbol(C.r1, Decl(a.d.ts, 10, 17))
>E.A : Symbol(E.A, Decl(a.d.ts, 0, 16))
>E : Symbol(E, Decl(a.d.ts, 0, 0))
>A : Symbol(E.A, Decl(a.d.ts, 0, 16))

static readonly r2 = NS.v;
>r2 : Symbol(C.r2, Decl(a.d.ts, 11, 29))
>NS.v : Symbol(NS.v, Decl(a.d.ts, 1, 28))
>NS : Symbol(NS, Decl(a.d.ts, 0, 33))
>v : Symbol(NS.v, Decl(a.d.ts, 1, 28))
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//// [tests/cases/compiler/ambientConstInitializerNonEnumReference.ts] ////

=== a.d.ts ===
declare enum E { A = 1, B = "b" }
>E : E
>A : E.A
>1 : 1
>B : E.B
>"b" : "b"

declare namespace NS { const v: 1; }
>NS : typeof NS
>v : 1

declare const obj: { readonly x: 1 };
>obj : { readonly x: 1; }
>x : 1

declare const e1 = E.A;
>e1 : E.A
>E.A : E.A
>E : typeof E
>A : E.A

declare const e2 = E["B"];
>e2 : E.B
>E["B"] : E.B
>E : typeof E
>"B" : "B"

declare const n1 = NS.v;
>n1 : 1
>NS.v : 1
>NS : typeof NS
>v : 1

declare const n2 = NS["v"];
>n2 : 1
>NS["v"] : 1
>NS : typeof NS
>"v" : "v"

declare const o1 = obj.x;
>o1 : 1
>obj.x : 1
>obj : { readonly x: 1; }
>x : 1

declare class C {
>C : C

static readonly r1 = E.A;
>r1 : E.A
>E.A : E.A
>E : typeof E
>A : E.A

static readonly r2 = NS.v;
>r2 : 1
>NS.v : 1
>NS : typeof NS
>v : 1
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
awaitOperandContextualTypeUnwrapsAwaited.ts(4,5): error TS2322: Type 'T' is not assignable to type 'Awaited<T>'.
Type 'number' is not assignable to type 'Awaited<T>'.
awaitOperandContextualTypeUnwrapsAwaited.ts(8,11): error TS2322: Type 'T' is not assignable to type 'Awaited<T>'.
Type 'number' is not assignable to type 'Awaited<T>'.


==== awaitOperandContextualTypeUnwrapsAwaited.ts (2 errors) ====
declare function make<U>(): PromiseLike<U>;

async function f<T extends number>(): Promise<Awaited<T>> {
return await make();
~~~~~~
!!! error TS2322: Type 'T' is not assignable to type 'Awaited<T>'.
!!! error TS2322: Type 'number' is not assignable to type 'Awaited<T>'.
}

async function g<T extends number>() {
const x: Awaited<T> = await make();
~
!!! error TS2322: Type 'T' is not assignable to type 'Awaited<T>'.
!!! error TS2322: Type 'number' is not assignable to type 'Awaited<T>'.
return x;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//// [tests/cases/compiler/awaitOperandContextualTypeUnwrapsAwaited.ts] ////

=== awaitOperandContextualTypeUnwrapsAwaited.ts ===
declare function make<U>(): PromiseLike<U>;
>make : Symbol(make, Decl(awaitOperandContextualTypeUnwrapsAwaited.ts, 0, 0))
>U : Symbol(U, Decl(awaitOperandContextualTypeUnwrapsAwaited.ts, 0, 22))
>PromiseLike : Symbol(PromiseLike, Decl(lib.es5.d.ts, --, --))
>U : Symbol(U, Decl(awaitOperandContextualTypeUnwrapsAwaited.ts, 0, 22))

async function f<T extends number>(): Promise<Awaited<T>> {
>f : Symbol(f, Decl(awaitOperandContextualTypeUnwrapsAwaited.ts, 0, 43))
>T : Symbol(T, Decl(awaitOperandContextualTypeUnwrapsAwaited.ts, 2, 17))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
>T : Symbol(T, Decl(awaitOperandContextualTypeUnwrapsAwaited.ts, 2, 17))

return await make();
>make : Symbol(make, Decl(awaitOperandContextualTypeUnwrapsAwaited.ts, 0, 0))
}

async function g<T extends number>() {
>g : Symbol(g, Decl(awaitOperandContextualTypeUnwrapsAwaited.ts, 4, 1))
>T : Symbol(T, Decl(awaitOperandContextualTypeUnwrapsAwaited.ts, 6, 17))

const x: Awaited<T> = await make();
>x : Symbol(x, Decl(awaitOperandContextualTypeUnwrapsAwaited.ts, 7, 9))
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
>T : Symbol(T, Decl(awaitOperandContextualTypeUnwrapsAwaited.ts, 6, 17))
>make : Symbol(make, Decl(awaitOperandContextualTypeUnwrapsAwaited.ts, 0, 0))

return x;
>x : Symbol(x, Decl(awaitOperandContextualTypeUnwrapsAwaited.ts, 7, 9))
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//// [tests/cases/compiler/awaitOperandContextualTypeUnwrapsAwaited.ts] ////

=== awaitOperandContextualTypeUnwrapsAwaited.ts ===
declare function make<U>(): PromiseLike<U>;
>make : <U>() => PromiseLike<U>

async function f<T extends number>(): Promise<Awaited<T>> {
>f : <T extends number>() => Promise<Awaited<T>>

return await make();
>await make() : T
>make() : PromiseLike<T>
>make : <U>() => PromiseLike<U>
}

async function g<T extends number>() {
>g : <T extends number>() => Promise<T>

const x: Awaited<T> = await make();
>x : Awaited<T>
>await make() : T
>make() : PromiseLike<T>
>make : <U>() => PromiseLike<U>

return x;
>x : Awaited<T>
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//// [tests/cases/compiler/bigintZeroIsDefinitelyFalsy.ts] ////

=== bigintZeroIsDefinitelyFalsy.ts ===
declare const x: 0n | 1n;
>x : Symbol(x, Decl(bigintZeroIsDefinitelyFalsy.ts, 0, 13))

const y = x && "a";
>y : Symbol(y, Decl(bigintZeroIsDefinitelyFalsy.ts, 1, 5))
>x : Symbol(x, Decl(bigintZeroIsDefinitelyFalsy.ts, 0, 13))

const z: 0n | "a" = x && "a";
>z : Symbol(z, Decl(bigintZeroIsDefinitelyFalsy.ts, 2, 5))
>x : Symbol(x, Decl(bigintZeroIsDefinitelyFalsy.ts, 0, 13))

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//// [tests/cases/compiler/bigintZeroIsDefinitelyFalsy.ts] ////

=== bigintZeroIsDefinitelyFalsy.ts ===
declare const x: 0n | 1n;
>x : 0n | 1n

const y = x && "a";
>y : "a" | 0n
>x && "a" : "a" | 0n
>x : 0n | 1n
>"a" : "a"

const z: 0n | "a" = x && "a";
>z : "a" | 0n
>x && "a" : "a" | 0n
>x : 0n | 1n
>"a" : "a"

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
classExtendsNullValuedIdentifier.ts(2,21): error TS2377: Constructors for derived classes must contain a 'super' call.
classExtendsNullValuedIdentifier.ts(4,40): error TS17005: A constructor cannot contain a 'super' call when its class extends 'null'.
classExtendsNullValuedIdentifier.ts(6,21): error TS2377: Constructors for derived classes must contain a 'super' call.


==== classExtendsNullValuedIdentifier.ts (3 errors) ====
const N = null;
class A extends N { constructor() { } }
~~~~~~~~~~~
!!! error TS2377: Constructors for derived classes must contain a 'super' call.
class B extends (null) { constructor() { } }
class C extends null { constructor() { super(); } }
~~~~~~~
!!! error TS17005: A constructor cannot contain a 'super' call when its class extends 'null'.
let n = null;
class D extends n { constructor() { } }
~~~~~~~~~~~
!!! error TS2377: Constructors for derived classes must contain a 'super' call.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//// [tests/cases/compiler/classExtendsNullValuedIdentifier.ts] ////

//// [classExtendsNullValuedIdentifier.ts]
const N = null;
class A extends N { constructor() { } }
class B extends (null) { constructor() { } }
class C extends null { constructor() { super(); } }
let n = null;
class D extends n { constructor() { } }


//// [classExtendsNullValuedIdentifier.js]
"use strict";
const N = null;
class A extends N {
constructor() { }
}
class B extends (null) {
constructor() { }
}
class C extends null {
constructor() { super(); }
}
let n = null;
class D extends n {
constructor() { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//// [tests/cases/compiler/classExtendsNullValuedIdentifier.ts] ////

=== classExtendsNullValuedIdentifier.ts ===
const N = null;
>N : Symbol(N, Decl(classExtendsNullValuedIdentifier.ts, 0, 5))

class A extends N { constructor() { } }
>A : Symbol(A, Decl(classExtendsNullValuedIdentifier.ts, 0, 15))
>N : Symbol(N, Decl(classExtendsNullValuedIdentifier.ts, 0, 5))

class B extends (null) { constructor() { } }
>B : Symbol(B, Decl(classExtendsNullValuedIdentifier.ts, 1, 39))

class C extends null { constructor() { super(); } }
>C : Symbol(C, Decl(classExtendsNullValuedIdentifier.ts, 2, 44))

let n = null;
>n : Symbol(n, Decl(classExtendsNullValuedIdentifier.ts, 4, 3))

class D extends n { constructor() { } }
>D : Symbol(D, Decl(classExtendsNullValuedIdentifier.ts, 4, 13))
>n : Symbol(n, Decl(classExtendsNullValuedIdentifier.ts, 4, 3))

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//// [tests/cases/compiler/classExtendsNullValuedIdentifier.ts] ////

=== classExtendsNullValuedIdentifier.ts ===
const N = null;
>N : any

class A extends N { constructor() { } }
>A : A
>N : any

class B extends (null) { constructor() { } }
>B : B
>(null) : null

class C extends null { constructor() { super(); } }
>C : C
>super() : void
>super : any

let n = null;
>n : any

class D extends n { constructor() { } }
>D : D
>n : any

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
classExtendsNullValuedIdentifier.ts(4,40): error TS17005: A constructor cannot contain a 'super' call when its class extends 'null'.


==== classExtendsNullValuedIdentifier.ts (1 errors) ====
const N = null;
class A extends N { constructor() { } }
class B extends (null) { constructor() { } }
class C extends null { constructor() { super(); } }
~~~~~~~
!!! error TS17005: A constructor cannot contain a 'super' call when its class extends 'null'.
let n = null;
class D extends n { constructor() { } }

Loading
Loading