-
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
Excess properties not checked for unannotated function #33507
Comments
So, this is a feature request to propagate the "freshness" flag to the function return type, and perform excess property checks when the return type contains this "freshness"? |
Would you want this to give you an error? function foo () {
return { x : 1, y : 2 }
}
//OK?
//Or excess property error?
const obj : { x : number } = foo() |
How about, type Fn = () => {
foo: string;
};
function blah () {
return {
foo: "foo",
bar: "bar"
}
}
//OK?
//Or excess property error?
const fn: Fn = () => blah();
//OK?
//Or excess property error?
const fn2: Fn = blah; |
How about, type Fn = () => { foo : string }[];
const fn : Fn = () => ["hello"].map(str => {
return {
foo : str,
//OK?
//Or excess property error?
bar : str,
};
}); Or, type Fn = () => { foo : string }[];
//Does this freshness propagate through generics?
function identity<T> (callback : () => T) : T {
return callback();
}
//OK?
//Or excess property error?
const fn : Fn = () => identity(() => ({
foo: "foo",
//Excess property
bar: "bar"
}));
//Does this freshness propagate through generics?
function identity2<T> (t : T) : T {
return t;
}
//OK?
//Or excess property error?
const fn2 : Fn = () => identity2({
foo: "foo",
//Excess property
bar: "bar"
}); |
Duplicate #12632, lots of others. |
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
TypeScript Version: 3.6.3.
Search Terms: excess property properties checks checking return type function annotation
Code
Are there plans to expand excess property checks so that this case is also covered?
Workaround: annotate function return type or use constructor
The text was updated successfully, but these errors were encountered: