-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compute flow types for function declarations #58411
Open
Andarist
wants to merge
1
commit into
microsoft:main
Choose a base branch
from
Andarist:narrow-down-functions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+200
−8
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
65 changes: 65 additions & 0 deletions
65
tests/baselines/reference/assertionTypePredicatesOnFunction1.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,65 @@ | ||
//// [tests/cases/conformance/controlFlow/assertionTypePredicatesOnFunction1.ts] //// | ||
|
||
=== assertionTypePredicatesOnFunction1.ts === | ||
// https://github.com/microsoft/TypeScript/issues/41232 | ||
|
||
interface LabelledFunction { | ||
>LabelledFunction : Symbol(LabelledFunction, Decl(assertionTypePredicatesOnFunction1.ts, 0, 0)) | ||
|
||
label: string; | ||
>label : Symbol(LabelledFunction.label, Decl(assertionTypePredicatesOnFunction1.ts, 2, 28)) | ||
} | ||
|
||
declare function assignLabel<T extends (...args: never) => unknown>( | ||
>assignLabel : Symbol(assignLabel, Decl(assertionTypePredicatesOnFunction1.ts, 4, 1)) | ||
>T : Symbol(T, Decl(assertionTypePredicatesOnFunction1.ts, 6, 29)) | ||
>args : Symbol(args, Decl(assertionTypePredicatesOnFunction1.ts, 6, 40)) | ||
|
||
fn: T, | ||
>fn : Symbol(fn, Decl(assertionTypePredicatesOnFunction1.ts, 6, 68)) | ||
>T : Symbol(T, Decl(assertionTypePredicatesOnFunction1.ts, 6, 29)) | ||
|
||
label: string, | ||
>label : Symbol(label, Decl(assertionTypePredicatesOnFunction1.ts, 7, 8)) | ||
|
||
): asserts fn is T & LabelledFunction; | ||
>fn : Symbol(fn, Decl(assertionTypePredicatesOnFunction1.ts, 6, 68)) | ||
>T : Symbol(T, Decl(assertionTypePredicatesOnFunction1.ts, 6, 29)) | ||
>LabelledFunction : Symbol(LabelledFunction, Decl(assertionTypePredicatesOnFunction1.ts, 0, 0)) | ||
|
||
function a() {} | ||
>a : Symbol(a, Decl(assertionTypePredicatesOnFunction1.ts, 9, 38)) | ||
|
||
assignLabel(a, "a"); | ||
>assignLabel : Symbol(assignLabel, Decl(assertionTypePredicatesOnFunction1.ts, 4, 1)) | ||
>a : Symbol(a, Decl(assertionTypePredicatesOnFunction1.ts, 9, 38)) | ||
|
||
a.label; | ||
>a.label : Symbol(LabelledFunction.label, Decl(assertionTypePredicatesOnFunction1.ts, 2, 28)) | ||
>a : Symbol(a, Decl(assertionTypePredicatesOnFunction1.ts, 9, 38)) | ||
>label : Symbol(LabelledFunction.label, Decl(assertionTypePredicatesOnFunction1.ts, 2, 28)) | ||
|
||
const b = function () {}; | ||
>b : Symbol(b, Decl(assertionTypePredicatesOnFunction1.ts, 15, 5)) | ||
|
||
assignLabel(b, "b"); | ||
>assignLabel : Symbol(assignLabel, Decl(assertionTypePredicatesOnFunction1.ts, 4, 1)) | ||
>b : Symbol(b, Decl(assertionTypePredicatesOnFunction1.ts, 15, 5)) | ||
|
||
b.label; | ||
>b.label : Symbol(LabelledFunction.label, Decl(assertionTypePredicatesOnFunction1.ts, 2, 28)) | ||
>b : Symbol(b, Decl(assertionTypePredicatesOnFunction1.ts, 15, 5)) | ||
>label : Symbol(LabelledFunction.label, Decl(assertionTypePredicatesOnFunction1.ts, 2, 28)) | ||
|
||
const c = () => {}; | ||
>c : Symbol(c, Decl(assertionTypePredicatesOnFunction1.ts, 19, 5)) | ||
|
||
assignLabel(c, "c"); | ||
>assignLabel : Symbol(assignLabel, Decl(assertionTypePredicatesOnFunction1.ts, 4, 1)) | ||
>c : Symbol(c, Decl(assertionTypePredicatesOnFunction1.ts, 19, 5)) | ||
|
||
c.label; | ||
>c.label : Symbol(LabelledFunction.label, Decl(assertionTypePredicatesOnFunction1.ts, 2, 28)) | ||
>c : Symbol(c, Decl(assertionTypePredicatesOnFunction1.ts, 19, 5)) | ||
>label : Symbol(LabelledFunction.label, Decl(assertionTypePredicatesOnFunction1.ts, 2, 28)) | ||
|
97 changes: 97 additions & 0 deletions
97
tests/baselines/reference/assertionTypePredicatesOnFunction1.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,97 @@ | ||
//// [tests/cases/conformance/controlFlow/assertionTypePredicatesOnFunction1.ts] //// | ||
|
||
=== assertionTypePredicatesOnFunction1.ts === | ||
// https://github.com/microsoft/TypeScript/issues/41232 | ||
|
||
interface LabelledFunction { | ||
label: string; | ||
>label : string | ||
> : ^^^^^^ | ||
} | ||
|
||
declare function assignLabel<T extends (...args: never) => unknown>( | ||
>assignLabel : <T extends (...args: never) => unknown>(fn: T, label: string) => asserts fn is T & LabelledFunction | ||
> : ^ ^^^^^^^^^^^^^ ^^ ^^^^^ ^^ ^^ ^^ ^^ ^^^^^ | ||
>args : never | ||
> : ^^^^^ | ||
|
||
fn: T, | ||
>fn : T | ||
> : ^ | ||
|
||
label: string, | ||
>label : string | ||
> : ^^^^^^ | ||
|
||
): asserts fn is T & LabelledFunction; | ||
|
||
function a() {} | ||
>a : () => void | ||
> : ^^^^^^^^^^ | ||
|
||
assignLabel(a, "a"); | ||
>assignLabel(a, "a") : void | ||
> : ^^^^ | ||
>assignLabel : <T extends (...args: never) => unknown>(fn: T, label: string) => asserts fn is T & LabelledFunction | ||
> : ^ ^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
>a : () => void | ||
> : ^^^^^^^^^^ | ||
>"a" : "a" | ||
> : ^^^ | ||
|
||
a.label; | ||
>a.label : string | ||
> : ^^^^^^ | ||
>a : (() => void) & LabelledFunction | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
>label : string | ||
> : ^^^^^^ | ||
|
||
const b = function () {}; | ||
>b : () => void | ||
> : ^^^^^^^^^^ | ||
>function () {} : () => void | ||
> : ^^^^^^^^^^ | ||
|
||
assignLabel(b, "b"); | ||
>assignLabel(b, "b") : void | ||
> : ^^^^ | ||
>assignLabel : <T extends (...args: never) => unknown>(fn: T, label: string) => asserts fn is T & LabelledFunction | ||
> : ^ ^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
>b : () => void | ||
> : ^^^^^^^^^^ | ||
>"b" : "b" | ||
> : ^^^ | ||
|
||
b.label; | ||
>b.label : string | ||
> : ^^^^^^ | ||
>b : (() => void) & LabelledFunction | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
>label : string | ||
> : ^^^^^^ | ||
|
||
const c = () => {}; | ||
>c : () => void | ||
> : ^^^^^^^^^^ | ||
>() => {} : () => void | ||
> : ^^^^^^^^^^ | ||
|
||
assignLabel(c, "c"); | ||
>assignLabel(c, "c") : void | ||
> : ^^^^ | ||
>assignLabel : <T extends (...args: never) => unknown>(fn: T, label: string) => asserts fn is T & LabelledFunction | ||
> : ^ ^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
>c : () => void | ||
> : ^^^^^^^^^^ | ||
>"c" : "c" | ||
> : ^^^ | ||
|
||
c.label; | ||
>c.label : string | ||
> : ^^^^^^ | ||
>c : (() => void) & LabelledFunction | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
>label : string | ||
> : ^^^^^^ | ||
|
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
25 changes: 25 additions & 0 deletions
25
tests/cases/conformance/controlFlow/assertionTypePredicatesOnFunction1.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,25 @@ | ||
// @strict: true | ||
// @noEmit: true | ||
|
||
// https://github.com/microsoft/TypeScript/issues/41232 | ||
|
||
interface LabelledFunction { | ||
label: string; | ||
} | ||
|
||
declare function assignLabel<T extends (...args: never) => unknown>( | ||
fn: T, | ||
label: string, | ||
): asserts fn is T & LabelledFunction; | ||
|
||
function a() {} | ||
assignLabel(a, "a"); | ||
a.label; | ||
|
||
const b = function () {}; | ||
assignLabel(b, "b"); | ||
b.label; | ||
|
||
const c = () => {}; | ||
assignLabel(c, "c"); | ||
c.label; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tbf... if this is something the plan would like to pull in, we probably should enable narrowing on just anything.
asserts
make it possible to expand all non-nullable types