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
asserts
keyword does not enhance hoisted function type, works on functions assigned to a variable
#41232
Labels
Milestone
Comments
phryneas
changed the title
Oct 25, 2020
asserts
keyword does not enhance hoisting function type, works on functions assigned to a variableasserts
keyword does not enhance hoisted function type, works on functions assigned to a variable
Same thing happens to classes: interface Labelled {
label: string;
}
function assignLabel <T> (value: T, label: string): asserts value is (T & Labelled) {
Object.assign(value, { label });
}
function a() { }
assignLabel(a, 'a');
console.info(a.label); // Property 'label' does not exist on type '() => void'.(2339)
const b = function b () { };
assignLabel(b, 'b');
console.info(b.label); // Works
class X {}
assignLabel(X, 'X');
X.label; // Property 'label' does not exist on type '() => void'.(2339)
const Y = class Y {}
assignLabel(Y, 'Y'); // Works
Y.label; |
I think I could look into it |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TypeScript Version: 4.0.2, 4.1.0-beta
Search Terms:
asserts function
Code
Expected behavior:
At least in runtime code coming after
assignLabel(a, 'a');
,a.label
should be accessible.Actual behavior:
Playground Link: link
The text was updated successfully, but these errors were encountered: