-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
Narrow generic conditional and indexed access return types when checking return statements #56941
base: main
Are you sure you want to change the base?
Conversation
@typescript-bot perf test this |
Heya @gabritto, I've started to run the regular perf test suite on this PR at a3a54ce. You can monitor the build here. Update: The results are in! |
This comment was marked as outdated.
This comment was marked as outdated.
@typescript-bot perf test this |
Heya @gabritto, I've started to run the regular perf test suite on this PR at 1b7489f. You can monitor the build here. Update: The results are in! |
Hey @gabritto, I've packed this into an installable tgz. You can install it for testing by referencing it in your
and then running There is also a playground for this build and an npm module you can use via |
@Andarist the playground, as requested |
@typescript-bot test it |
@gabritto Here are the results of running the user tests with tsc comparing Something interesting changed - please have a look. Details
|
Hey @gabritto, the results of running the DT tests are ready. Everything looks the same! |
@gabritto Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
@gabritto Here are the results of running the top 400 repos with tsc comparing Something interesting changed - please have a look. Details
|
|
Good error,
Good error, error type masking.
Theoretically correct error,
Error position changed from expression to conditional branches, need to move the
Good error,
Seem like existing errors.
src/tsconfig.tsec.json
Good error,
Theoretically correct error,
???
Error position changed from expression to conditional branches, need to move the
Error position changed from expression to conditional branches, need to move the |
@typescript-bot test it |
@gabritto Here are the results of running the user tests with tsc comparing Something interesting changed - please have a look. Details
|
Hey @gabritto, the results of running the DT tests are ready. Everything looks the same! |
@gabritto Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
@typescript-bot perf test this faster |
@gabritto Here are the results of running the top 400 repos with tsc comparing Something interesting changed - please have a look. Details
|
@gabritto Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
@typescript-bot perf test this faster |
@gabritto Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
Conditional return expression state of affairsSummary of error changes in user tests + top400:
Representative reduced examples:New errors likely to be bugs: const rboolean =
/^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i;
declare function getAttr(
elem: any,
name: string | undefined,
xmlMode?: boolean,
): Record<string, string> | string | undefined;
function getProp(
el: Element,
name: string,
xmlMode?: boolean,
): string | undefined | Element[keyof Element] {
return name in el
? // @ts-expect-error TS doesn't like us accessing the value directly here.
el[name]
: !xmlMode && rboolean.test(name)
? getAttr(el, name, false) !== undefined
: getAttr(el, name, xmlMode);
} interface IExpression {
[pattern: string]: boolean;
}
function patternListToIExpression(...patterns: string[]): IExpression {
return patterns.length ?
patterns.reduce((glob, cur) => { glob[cur] = true; return glob; }, Object.create(null)) :
undefined;
} New errors unlikely to be bugs: type ContextKeyValue = null | undefined | boolean | number | string
| Array<null | undefined | boolean | number | string>
| Record<string, null | undefined | boolean | number | string>;
interface IContext {
getValue<T extends ContextKeyValue = ContextKeyValue>(key: string): T | undefined;
}
class OverlayContext implements IContext {
private parent!: IContext;
private overlay!: ReadonlyMap<string, any>;
getValue<T>(key: string): T | undefined {
return this.overlay.has(key)
? this.overlay.get(key)
: this.parent.getValue(key); // The type of this call is `ContextKeyValue`, which is not assignable to `T`.
}
} Position change: interface VNode {
componentInstance?: { _node: VNode };
}
interface VNodeWithData extends VNode {
data: object;
}
function locateNode(vnode: VNode | VNodeWithData): VNodeWithData {
// @ts-expect-error
return vnode.componentInstance // Error currently happens on this line and is supressed
? locateNode(vnode.componentInstance._node)
: vnode // With change, error shifts to this line
} |
Fixes #33912.
Fixes #33014.