Skip to content

Inconsistent excess property checking: ref<T>() errors, computed<T>() doesn't #13443

Closed as not planned
@arkandias

Description

@arkandias

Vue version

3.5.16

Link to minimal reproduction

https://play.vuejs.org/#eNqNkk1PwzAMhv+KlQubNG0HOO2jEqAdxmGgsWMupfW6jjaJEncrqvrfcVIoFQLELXltv34cpxG3xkzPFYq5WLrE5obAIVUGilhlKynISRFJlZdGW4IGEl2aijCdgMUDtHCwugQp2EGKhVRSzWawUYlWLneEigDrBJ0DY7VBS2+QHDF5zVU29wbLfTQaA1qrrZv03p2aanTqimQwI7jkdNxxy1WoayCegyPLRtBGo0Yq8IoURywKLcXECy9euGhbpEFoxwtgurXvNnS9/2jL1j3BN3/GWUXw3zZdn63uBpNqOetelt+RL4SlKWJCvgE0TT9Y2w6Ensmry9mgRkx4Jwx/yLPpyWnFiwtYUnj4vED7aCjn4aSYQ4j4WMy4l4egka0wcIcav40f9JOrvSbFk0WH9szb7WMU2wypC6+ft1jzuQ+WOq0Kzv4juEOni8ozdml3lUoZe5AXaDfhy/EC9m5d81dyn0N5UJ/Zhvzw9/xz/Tb6F+719CbU8Y5E+w7Z9P3w

Steps to reproduce

import { computed, ref } from "vue";

// Inconsistent excess property checking: ref<T>() errors, computed<T>() doesn't
const withRef = ref<{ a: string }>({
  a: "hello",
  b: "world", // Error
});
const withComputed = computed<{ a: string }>(() => ({
  a: "hello",
  b: "world", // No error
}));

What is expected?

TypeScript should raise Object literal may only specify known properties, and 'b' does not exist in type '{ a: string; }'. ts(2353) for withComputed, as it does for withRef.

What is actually happening?

TypeScript does not raise any error for withComputed, though it definitely should.

If, for some technical reason, type checking cannot be enforced with computed in the same way it is with ref, this behavior should be documented.

System Info

Any additional comments?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions