| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
TypeScript Bot (@typescript-bot) pack this |
Sorry, something went wrong.
|
Heya Daniel Rosenwasser (@DanielRosenwasser), I've started to run the extended test suite on this PR at dd07cdc. You can monitor the build here. |
Sorry, something went wrong.
|
Heya Daniel Rosenwasser (@DanielRosenwasser), I've started to run the tarball bundle task on this PR at dd07cdc. You can monitor the build here. |
Sorry, something went wrong.
|
Heya Daniel Rosenwasser (@DanielRosenwasser), I've started to run the parallelized community code test suite on this PR at dd07cdc. You can monitor the build here. |
Sorry, something went wrong.
|
Heya Daniel Rosenwasser (@DanielRosenwasser), I've started to run the perf test suite on this PR at dd07cdc. You can monitor the build here. Update: The results are in! |
Sorry, something went wrong.
|
Heya Daniel Rosenwasser (@DanielRosenwasser), I've started to run the parallelized Definitely Typed test suite on this PR at dd07cdc. You can monitor the build here. |
Sorry, something went wrong.
|
The user suite test run you requested has finished and failed. I've opened a PR with the baseline diff from master. |
Sorry, something went wrong.
|
Daniel Rosenwasser (@DanielRosenwasser) Comparison Report - main..46266
System
Hosts
Scenarios
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Sorry, something went wrong.
|
TypeScript Bot (@typescript-bot) perf test this |
Sorry, something went wrong.
|
Heya Anders Hejlsberg (@ahejlsberg), I've started to run the perf test suite on this PR at 76fbe25. You can monitor the build here. Update: The results are in! |
Sorry, something went wrong.
| const declaration = symbol.valueDeclaration; | ||
| if (declaration && isBindingElement(declaration) && !declaration.initializer && !declaration.dotDotDotToken && declaration.parent.elements.length >= 2) { | ||
| const parent = declaration.parent.parent; | ||
| if (parent.kind === SyntaxKind.VariableDeclaration && getCombinedNodeFlags(declaration) && NodeFlags.Const || parent.kind === SyntaxKind.Parameter) { |
There was a problem hiding this comment.
Small typo here:
| if (parent.kind === SyntaxKind.VariableDeclaration && getCombinedNodeFlags(declaration) && NodeFlags.Const || parent.kind === SyntaxKind.Parameter) { | |
| if (parent.kind === SyntaxKind.VariableDeclaration && getCombinedNodeFlags(declaration) & NodeFlags.Const || parent.kind === SyntaxKind.Parameter) { | |
Sorry, something went wrong.
There was a problem hiding this comment.
Oh, good catch!
Sorry, something went wrong.
|
TypeScript Bot (@typescript-bot) perf test this faster |
Sorry, something went wrong.
|
Heya Anders Hejlsberg (@ahejlsberg), I've started to run the abridged perf test suite on this PR at cf546e8. You can monitor the build here. Update: The results are in! |
Sorry, something went wrong.
|
Heya Anders Hejlsberg (@ahejlsberg), I've started to run the perf test suite on this PR at cf546e8. You can monitor the build here. Update: The results are in! |
Sorry, something went wrong.
|
Anders Hejlsberg (@ahejlsberg) Comparison Report - main..46266
System
Hosts
Scenarios
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Sorry, something went wrong.
|
Anders Hejlsberg (@ahejlsberg) Comparison Report - main..46266
System
Hosts
Scenarios
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Sorry, something went wrong.
|
This is super exciting, thanks for working on this Anders Hejlsberg (@ahejlsberg)! I just ran into this today when working with Result types. |
Sorry, something went wrong.
…t#46266) * CFA for dependent variables destructured from discriminated union * Accept new baselines * Add tests * Limit calls to isSymbolAssigned * Fix wrong operator
|
Daniel Rosenwasser (@DanielRosenwasser) maybe it's worth adding this feature to the 4.6 beta blog post: The blog post does not mention object restructuring, only tuple/union destructuring, but I checked the 4.6 nightly playground and it works with objects too now, which is highly anticipated by React users (more than the example showcased in the blog post IMHO) Edit: oups actually I'm wrong it's not yet 100% good enough for React, and the following still fails: import React from "react";
type ItemData =
| { kind: 'user', name: string }
| { kind: 'company', id: string }
function Item({ kind, ...data }: ItemData) {
if (kind === 'user') {
<div>{data.id}</div>
}
if (kind === 'company') {
<div>{data.name}</div>
}
return null;
}But the following now works: type ItemData2 =
| { kind: 'user', data: {name: string} }
| { kind: 'company', data: {id: string} }
function Item2({ kind, data }: ItemData2) {
if (kind === 'user') {
<div>{data.name}</div>
}
if (kind === 'company') {
<div>{data.id}</div>
}
return null;
}Still worth highlighting that in the post :) |
Sorry, something went wrong.
|
Seems like the difference there is the spread, right? Okay, that's a good call, we must have missed that. I will likely add that to the RC post. |
Sorry, something went wrong.
|
Awesome! Thank you so much❤️ |
Sorry, something went wrong.
|
Just a question of understanding: Is the support for the spread syntax planned for a bugfix release or for a minor version? Or is it currently not being planned to be changed / given priority? |
Sorry, something went wrong.
|
Luxalpa (@luxalpa) tracked here: #46680 Would also like to see this implemented 😄 |
Sorry, something went wrong.
|
I've noticed that this feature doesn't seem to play nice with default values: type T = {
flag: true;
a: number;
} | {
flag: false;
a: string;
}
// This code works if you remove the "= true"
({ flag = true, a }: T) => {
if (flag) {
a.toFixed(); // thinks it can be either a string or number again
} else {
a.toUpperCase(); // same as above
}
}
Is this also covered by #46680 or is there another reason it doesn't work? |
Sorry, something went wrong.
|
Gareth Chen (@50an6xy06r6n) that feels like a bug |
Sorry, something went wrong.
|
It's a design limitation, but one we could consider removing. We only do CFA for dependent destructured parameters when they're declared without initializers because it adds complexity to consider the contribution the initializer might make to the inferred declared type of the parameter. |
Sorry, something went wrong.
|
Anders Hejlsberg (@ahejlsberg) intuitively it feels like it should work. In my case (react), the way props work means you have to pass parameters as an object, though I realized that there's other ways to set the default value. |
Sorry, something went wrong.
|
This also does not work when destructuring a nested discriminated union type. See playground link here. I assume this is because of this line in the PR description:
Since the object is nested, the parent type being destructured is not the discriminated union. Still, it's a shame this does not work. |
Sorry, something went wrong.
|
I am currently running into issues with this (or a related) analysis. I have a union [A, B] | [C, D] | [E, F] and functions isA() isC() isE() and regardless of destructuring or not, narrowing the first tuple member cannot narrow the second tuple member. |
Sorry, something went wrong.
|
That's a great feature, I personally use it to make global variables dependant on each other: interface BrowserAPI {
context: "browser";
doBrowserThing(): void;
doNodeThing: never;
}
interface NodeAPI {
context: "node";
doNodeThing(): void;
doBrowserThing: never;
}
declare const api: BrowserAPI | NodeAPI;
const { context, doNodeThing, doBrowserThing } = api;
if (context === "browser") {
doBrowserThing();
} else {
doNodeThing();
}But it lacks one thing necessary for my usecase: a way to use destructuring in a declaration file (.d.ts). I can't actually perform destructuring, because all the API is defined on the global object at run-time. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
This PR implements control flow analysis for dependent parameters and variables declared by destructuring discriminated unions. Specifically, when non-rest binding elements are declared as const variables or const-like parameters (parameters for which there are no assignments in the function body) and the parent type for the destructuring is a discriminated union type, conditional checks for variables destructured from discriminant properties now affect the types of other variables declared in the same destructuring.
Some examples:
Fixes #10830.
Fixes #35283.
Fixes #38020.
Fixes #46143.