-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed contravariant inferences from annotated optional parameters (#5…
- Loading branch information
Showing
7 changed files
with
182 additions
and
1 deletion.
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
25 changes: 25 additions & 0 deletions
25
tests/baselines/reference/contravariantOnlyInferenceWithAnnotatedOptionalParameter.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,25 @@ | ||
//// [tests/cases/compiler/contravariantOnlyInferenceWithAnnotatedOptionalParameter.ts] //// | ||
|
||
=== contravariantOnlyInferenceWithAnnotatedOptionalParameter.ts === | ||
// repro https://github.com/microsoft/TypeScript/issues/55394 | ||
|
||
declare function filter<T>(predicate: (value: T, index: number) => boolean): T; | ||
>filter : Symbol(filter, Decl(contravariantOnlyInferenceWithAnnotatedOptionalParameter.ts, 0, 0)) | ||
>T : Symbol(T, Decl(contravariantOnlyInferenceWithAnnotatedOptionalParameter.ts, 2, 24)) | ||
>predicate : Symbol(predicate, Decl(contravariantOnlyInferenceWithAnnotatedOptionalParameter.ts, 2, 27)) | ||
>value : Symbol(value, Decl(contravariantOnlyInferenceWithAnnotatedOptionalParameter.ts, 2, 39)) | ||
>T : Symbol(T, Decl(contravariantOnlyInferenceWithAnnotatedOptionalParameter.ts, 2, 24)) | ||
>index : Symbol(index, Decl(contravariantOnlyInferenceWithAnnotatedOptionalParameter.ts, 2, 48)) | ||
>T : Symbol(T, Decl(contravariantOnlyInferenceWithAnnotatedOptionalParameter.ts, 2, 24)) | ||
|
||
const a = filter((pose?: number) => true); | ||
>a : Symbol(a, Decl(contravariantOnlyInferenceWithAnnotatedOptionalParameter.ts, 3, 5)) | ||
>filter : Symbol(filter, Decl(contravariantOnlyInferenceWithAnnotatedOptionalParameter.ts, 0, 0)) | ||
>pose : Symbol(pose, Decl(contravariantOnlyInferenceWithAnnotatedOptionalParameter.ts, 3, 18)) | ||
|
||
const b = filter((pose?: number, _?: number) => true); | ||
>b : Symbol(b, Decl(contravariantOnlyInferenceWithAnnotatedOptionalParameter.ts, 4, 5)) | ||
>filter : Symbol(filter, Decl(contravariantOnlyInferenceWithAnnotatedOptionalParameter.ts, 0, 0)) | ||
>pose : Symbol(pose, Decl(contravariantOnlyInferenceWithAnnotatedOptionalParameter.ts, 4, 18)) | ||
>_ : Symbol(_, Decl(contravariantOnlyInferenceWithAnnotatedOptionalParameter.ts, 4, 32)) | ||
|
28 changes: 28 additions & 0 deletions
28
tests/baselines/reference/contravariantOnlyInferenceWithAnnotatedOptionalParameter.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,28 @@ | ||
//// [tests/cases/compiler/contravariantOnlyInferenceWithAnnotatedOptionalParameter.ts] //// | ||
|
||
=== contravariantOnlyInferenceWithAnnotatedOptionalParameter.ts === | ||
// repro https://github.com/microsoft/TypeScript/issues/55394 | ||
|
||
declare function filter<T>(predicate: (value: T, index: number) => boolean): T; | ||
>filter : <T>(predicate: (value: T, index: number) => boolean) => T | ||
>predicate : (value: T, index: number) => boolean | ||
>value : T | ||
>index : number | ||
|
||
const a = filter((pose?: number) => true); | ||
>a : number | undefined | ||
>filter((pose?: number) => true) : number | undefined | ||
>filter : <T>(predicate: (value: T, index: number) => boolean) => T | ||
>(pose?: number) => true : (pose?: number) => true | ||
>pose : number | undefined | ||
>true : true | ||
|
||
const b = filter((pose?: number, _?: number) => true); | ||
>b : number | undefined | ||
>filter((pose?: number, _?: number) => true) : number | undefined | ||
>filter : <T>(predicate: (value: T, index: number) => boolean) => T | ||
>(pose?: number, _?: number) => true : (pose?: number, _?: number) => true | ||
>pose : number | undefined | ||
>_ : number | undefined | ||
>true : true | ||
|
41 changes: 41 additions & 0 deletions
41
tests/baselines/reference/contravariantOnlyInferenceWithAnnotatedOptionalParameterJs.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,41 @@ | ||
//// [tests/cases/compiler/contravariantOnlyInferenceWithAnnotatedOptionalParameterJs.ts] //// | ||
|
||
=== index.js === | ||
/** | ||
* @template T | ||
* @param {(value: T, index: number) => boolean} predicate | ||
* @returns {T} | ||
*/ | ||
function filter(predicate) { | ||
>filter : Symbol(filter, Decl(index.js, 0, 0)) | ||
>predicate : Symbol(predicate, Decl(index.js, 5, 16)) | ||
|
||
return /** @type {any} */ (null); | ||
} | ||
|
||
const a = filter( | ||
>a : Symbol(a, Decl(index.js, 9, 5)) | ||
>filter : Symbol(filter, Decl(index.js, 0, 0)) | ||
|
||
/** | ||
* @param {number} [pose] | ||
*/ | ||
(pose) => true | ||
>pose : Symbol(pose, Decl(index.js, 13, 3)) | ||
|
||
); | ||
|
||
const b = filter( | ||
>b : Symbol(b, Decl(index.js, 16, 5)) | ||
>filter : Symbol(filter, Decl(index.js, 0, 0)) | ||
|
||
/** | ||
* @param {number} [pose] | ||
* @param {number} [_] | ||
*/ | ||
(pose, _) => true | ||
>pose : Symbol(pose, Decl(index.js, 21, 3)) | ||
>_ : Symbol(_, Decl(index.js, 21, 8)) | ||
|
||
); | ||
|
48 changes: 48 additions & 0 deletions
48
tests/baselines/reference/contravariantOnlyInferenceWithAnnotatedOptionalParameterJs.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,48 @@ | ||
//// [tests/cases/compiler/contravariantOnlyInferenceWithAnnotatedOptionalParameterJs.ts] //// | ||
|
||
=== index.js === | ||
/** | ||
* @template T | ||
* @param {(value: T, index: number) => boolean} predicate | ||
* @returns {T} | ||
*/ | ||
function filter(predicate) { | ||
>filter : <T>(predicate: (value: T, index: number) => boolean) => T | ||
>predicate : (value: T, index: number) => boolean | ||
|
||
return /** @type {any} */ (null); | ||
>(null) : any | ||
} | ||
|
||
const a = filter( | ||
>a : number | undefined | ||
>filter( /** * @param {number} [pose] */ (pose) => true) : number | undefined | ||
>filter : <T>(predicate: (value: T, index: number) => boolean) => T | ||
|
||
/** | ||
* @param {number} [pose] | ||
*/ | ||
(pose) => true | ||
>(pose) => true : (pose?: number | undefined) => true | ||
>pose : number | undefined | ||
>true : true | ||
|
||
); | ||
|
||
const b = filter( | ||
>b : number | undefined | ||
>filter( /** * @param {number} [pose] * @param {number} [_] */ (pose, _) => true) : number | undefined | ||
>filter : <T>(predicate: (value: T, index: number) => boolean) => T | ||
|
||
/** | ||
* @param {number} [pose] | ||
* @param {number} [_] | ||
*/ | ||
(pose, _) => true | ||
>(pose, _) => true : (pose?: number | undefined, _?: number | undefined) => true | ||
>pose : number | undefined | ||
>_ : number | undefined | ||
>true : true | ||
|
||
); | ||
|
8 changes: 8 additions & 0 deletions
8
tests/cases/compiler/contravariantOnlyInferenceWithAnnotatedOptionalParameter.ts
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,8 @@ | ||
// @strict: true | ||
// @noEmit: true | ||
|
||
// repro https://github.com/microsoft/TypeScript/issues/55394 | ||
|
||
declare function filter<T>(predicate: (value: T, index: number) => boolean): T; | ||
const a = filter((pose?: number) => true); | ||
const b = filter((pose?: number, _?: number) => true); |
29 changes: 29 additions & 0 deletions
29
tests/cases/compiler/contravariantOnlyInferenceWithAnnotatedOptionalParameterJs.ts
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,29 @@ | ||
// @strict: true | ||
// @checkJs: true | ||
// @noEmit: true | ||
|
||
// @filename: index.js | ||
|
||
/** | ||
* @template T | ||
* @param {(value: T, index: number) => boolean} predicate | ||
* @returns {T} | ||
*/ | ||
function filter(predicate) { | ||
return /** @type {any} */ (null); | ||
} | ||
|
||
const a = filter( | ||
/** | ||
* @param {number} [pose] | ||
*/ | ||
(pose) => true | ||
); | ||
|
||
const b = filter( | ||
/** | ||
* @param {number} [pose] | ||
* @param {number} [_] | ||
*/ | ||
(pose, _) => true | ||
); |