You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The empty type does not trigger warning about extra properties. This is intentional behavior -- it doesn't make sense to error when there is no valid property name you could write.
Note that if f or g had some properties, you would see an error.
Fair enough that it's intentional, but in my particular case, it would be useful to have an error when returning fields not in {}. Consider:
interface CoreData {
name: string
}
interface Response<ExtraData> {
core_data: CoreData
extra_data?: ExtraData
}
function foo(): Response<{age: number}> {
return {
core_data: { name: "laphroaig" },
extra_data: { age: 18 },
}
}
function bar(): Response<{}> {
return {
core_data: { name: "laphroaig" },
extra_data: { age: 18 }, // woops! should be no extra data here
}
}
I want bar to be an error, because I didn't meant to include any extra fields. Is there a way to express this rule in TypeScript? Perhaps something other than {} ?
// Use any suitably-unlikely thing to write. Maybe 'ϞϞ(๑⚈ ․̫ ⚈๑)'typeEmptyType={'I really meant empty'?: void}`;functionbar(): Response<EmptyType>{/*... works as you'd like now ... */}
Just as in #3755, I would expect extra parameters from return values to produce an error.
On the playground:
Neither f nor g produce an error. Calling h does, per #3755.
I would expect f and g to produce errors too.
The text was updated successfully, but these errors were encountered: