-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
No contextual typing from return types for boolean literals (#48380)
* No contextual typing from return types for boolean literals * Accept new baselines * Add regression tests
- Loading branch information
1 parent
e62f960
commit 3f483d8
Showing
7 changed files
with
230 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
tests/baselines/reference/contextuallyTypedBooleanLiterals.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
//// [contextuallyTypedBooleanLiterals.ts] | ||
// Repro from #48363 | ||
|
||
type Box<T> = { | ||
get: () => T, | ||
set: (value: T) => void | ||
} | ||
|
||
declare function box<T>(value: T): Box<T>; | ||
|
||
const bn1 = box(0); // Box<number> | ||
const bn2: Box<number> = box(0); // Ok | ||
|
||
const bb1 = box(false); // Box<boolean> | ||
const bb2: Box<boolean> = box(false); // Error, box<false> not assignable to Box<boolean> | ||
|
||
// Repro from #48150 | ||
|
||
interface Observable<T> | ||
{ | ||
(): T; | ||
(value: T): any; | ||
} | ||
|
||
declare function observable<T>(value: T): Observable<T>; | ||
|
||
const x: Observable<boolean> = observable(false); | ||
|
||
|
||
//// [contextuallyTypedBooleanLiterals.js] | ||
"use strict"; | ||
// Repro from #48363 | ||
var bn1 = box(0); // Box<number> | ||
var bn2 = box(0); // Ok | ||
var bb1 = box(false); // Box<boolean> | ||
var bb2 = box(false); // Error, box<false> not assignable to Box<boolean> | ||
var x = observable(false); | ||
|
||
|
||
//// [contextuallyTypedBooleanLiterals.d.ts] | ||
declare type Box<T> = { | ||
get: () => T; | ||
set: (value: T) => void; | ||
}; | ||
declare function box<T>(value: T): Box<T>; | ||
declare const bn1: Box<number>; | ||
declare const bn2: Box<number>; | ||
declare const bb1: Box<boolean>; | ||
declare const bb2: Box<boolean>; | ||
interface Observable<T> { | ||
(): T; | ||
(value: T): any; | ||
} | ||
declare function observable<T>(value: T): Observable<T>; | ||
declare const x: Observable<boolean>; |
70 changes: 70 additions & 0 deletions
70
tests/baselines/reference/contextuallyTypedBooleanLiterals.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
=== tests/cases/compiler/contextuallyTypedBooleanLiterals.ts === | ||
// Repro from #48363 | ||
|
||
type Box<T> = { | ||
>Box : Symbol(Box, Decl(contextuallyTypedBooleanLiterals.ts, 0, 0)) | ||
>T : Symbol(T, Decl(contextuallyTypedBooleanLiterals.ts, 2, 9)) | ||
|
||
get: () => T, | ||
>get : Symbol(get, Decl(contextuallyTypedBooleanLiterals.ts, 2, 15)) | ||
>T : Symbol(T, Decl(contextuallyTypedBooleanLiterals.ts, 2, 9)) | ||
|
||
set: (value: T) => void | ||
>set : Symbol(set, Decl(contextuallyTypedBooleanLiterals.ts, 3, 17)) | ||
>value : Symbol(value, Decl(contextuallyTypedBooleanLiterals.ts, 4, 10)) | ||
>T : Symbol(T, Decl(contextuallyTypedBooleanLiterals.ts, 2, 9)) | ||
} | ||
|
||
declare function box<T>(value: T): Box<T>; | ||
>box : Symbol(box, Decl(contextuallyTypedBooleanLiterals.ts, 5, 1)) | ||
>T : Symbol(T, Decl(contextuallyTypedBooleanLiterals.ts, 7, 21)) | ||
>value : Symbol(value, Decl(contextuallyTypedBooleanLiterals.ts, 7, 24)) | ||
>T : Symbol(T, Decl(contextuallyTypedBooleanLiterals.ts, 7, 21)) | ||
>Box : Symbol(Box, Decl(contextuallyTypedBooleanLiterals.ts, 0, 0)) | ||
>T : Symbol(T, Decl(contextuallyTypedBooleanLiterals.ts, 7, 21)) | ||
|
||
const bn1 = box(0); // Box<number> | ||
>bn1 : Symbol(bn1, Decl(contextuallyTypedBooleanLiterals.ts, 9, 5)) | ||
>box : Symbol(box, Decl(contextuallyTypedBooleanLiterals.ts, 5, 1)) | ||
|
||
const bn2: Box<number> = box(0); // Ok | ||
>bn2 : Symbol(bn2, Decl(contextuallyTypedBooleanLiterals.ts, 10, 5)) | ||
>Box : Symbol(Box, Decl(contextuallyTypedBooleanLiterals.ts, 0, 0)) | ||
>box : Symbol(box, Decl(contextuallyTypedBooleanLiterals.ts, 5, 1)) | ||
|
||
const bb1 = box(false); // Box<boolean> | ||
>bb1 : Symbol(bb1, Decl(contextuallyTypedBooleanLiterals.ts, 12, 5)) | ||
>box : Symbol(box, Decl(contextuallyTypedBooleanLiterals.ts, 5, 1)) | ||
|
||
const bb2: Box<boolean> = box(false); // Error, box<false> not assignable to Box<boolean> | ||
>bb2 : Symbol(bb2, Decl(contextuallyTypedBooleanLiterals.ts, 13, 5)) | ||
>Box : Symbol(Box, Decl(contextuallyTypedBooleanLiterals.ts, 0, 0)) | ||
>box : Symbol(box, Decl(contextuallyTypedBooleanLiterals.ts, 5, 1)) | ||
|
||
// Repro from #48150 | ||
|
||
interface Observable<T> | ||
>Observable : Symbol(Observable, Decl(contextuallyTypedBooleanLiterals.ts, 13, 37)) | ||
>T : Symbol(T, Decl(contextuallyTypedBooleanLiterals.ts, 17, 21)) | ||
{ | ||
(): T; | ||
>T : Symbol(T, Decl(contextuallyTypedBooleanLiterals.ts, 17, 21)) | ||
|
||
(value: T): any; | ||
>value : Symbol(value, Decl(contextuallyTypedBooleanLiterals.ts, 20, 3)) | ||
>T : Symbol(T, Decl(contextuallyTypedBooleanLiterals.ts, 17, 21)) | ||
} | ||
|
||
declare function observable<T>(value: T): Observable<T>; | ||
>observable : Symbol(observable, Decl(contextuallyTypedBooleanLiterals.ts, 21, 1)) | ||
>T : Symbol(T, Decl(contextuallyTypedBooleanLiterals.ts, 23, 28)) | ||
>value : Symbol(value, Decl(contextuallyTypedBooleanLiterals.ts, 23, 31)) | ||
>T : Symbol(T, Decl(contextuallyTypedBooleanLiterals.ts, 23, 28)) | ||
>Observable : Symbol(Observable, Decl(contextuallyTypedBooleanLiterals.ts, 13, 37)) | ||
>T : Symbol(T, Decl(contextuallyTypedBooleanLiterals.ts, 23, 28)) | ||
|
||
const x: Observable<boolean> = observable(false); | ||
>x : Symbol(x, Decl(contextuallyTypedBooleanLiterals.ts, 25, 5)) | ||
>Observable : Symbol(Observable, Decl(contextuallyTypedBooleanLiterals.ts, 13, 37)) | ||
>observable : Symbol(observable, Decl(contextuallyTypedBooleanLiterals.ts, 21, 1)) | ||
|
61 changes: 61 additions & 0 deletions
61
tests/baselines/reference/contextuallyTypedBooleanLiterals.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
=== tests/cases/compiler/contextuallyTypedBooleanLiterals.ts === | ||
// Repro from #48363 | ||
|
||
type Box<T> = { | ||
>Box : Box<T> | ||
|
||
get: () => T, | ||
>get : () => T | ||
|
||
set: (value: T) => void | ||
>set : (value: T) => void | ||
>value : T | ||
} | ||
|
||
declare function box<T>(value: T): Box<T>; | ||
>box : <T>(value: T) => Box<T> | ||
>value : T | ||
|
||
const bn1 = box(0); // Box<number> | ||
>bn1 : Box<number> | ||
>box(0) : Box<number> | ||
>box : <T>(value: T) => Box<T> | ||
>0 : 0 | ||
|
||
const bn2: Box<number> = box(0); // Ok | ||
>bn2 : Box<number> | ||
>box(0) : Box<number> | ||
>box : <T>(value: T) => Box<T> | ||
>0 : 0 | ||
|
||
const bb1 = box(false); // Box<boolean> | ||
>bb1 : Box<boolean> | ||
>box(false) : Box<boolean> | ||
>box : <T>(value: T) => Box<T> | ||
>false : false | ||
|
||
const bb2: Box<boolean> = box(false); // Error, box<false> not assignable to Box<boolean> | ||
>bb2 : Box<boolean> | ||
>box(false) : Box<boolean> | ||
>box : <T>(value: T) => Box<T> | ||
>false : false | ||
|
||
// Repro from #48150 | ||
|
||
interface Observable<T> | ||
{ | ||
(): T; | ||
(value: T): any; | ||
>value : T | ||
} | ||
|
||
declare function observable<T>(value: T): Observable<T>; | ||
>observable : <T>(value: T) => Observable<T> | ||
>value : T | ||
|
||
const x: Observable<boolean> = observable(false); | ||
>x : Observable<boolean> | ||
>observable(false) : Observable<boolean> | ||
>observable : <T>(value: T) => Observable<T> | ||
>false : false | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// @strict: true | ||
// @declaration: true | ||
|
||
// @strict: true | ||
// @declaration: true | ||
|
||
// Repro from #48363 | ||
|
||
type Box<T> = { | ||
get: () => T, | ||
set: (value: T) => void | ||
} | ||
|
||
declare function box<T>(value: T): Box<T>; | ||
|
||
const bn1 = box(0); // Box<number> | ||
const bn2: Box<number> = box(0); // Ok | ||
|
||
const bb1 = box(false); // Box<boolean> | ||
const bb2: Box<boolean> = box(false); // Error, box<false> not assignable to Box<boolean> | ||
|
||
// Repro from #48150 | ||
|
||
interface Observable<T> | ||
{ | ||
(): T; | ||
(value: T): any; | ||
} | ||
|
||
declare function observable<T>(value: T): Observable<T>; | ||
|
||
const x: Observable<boolean> = observable(false); |