Closed as not planned
Description
π Search Terms
isolatedDeclarations, "as const", "satisfies"
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ
β― Playground Link
π» Code
type T = { prop: string };
export const one = {
prop: '',
};
export const two = {
prop: '',
} as const;
// errors :(
export const three = {
prop: '',
} satisfies T;
// errors :(
export const four = {
prop: '',
} as const satisfies T;
π Actual behavior
three
and four
both have errors, even though their satisfies
-less counterparts do not have errors.
π Expected behavior
all four variables should not error
Additional information about the issue
I guess that currently the presence of satisfies
causes a different code path that ignores whether the underlying expression would be valid?
It would be good if TS was able to "look past" the satisfies
so it can treat the code the same as if there was no satisfies
.
This behaviour encourages you to do hacky things like this to "work around" the limitation.
export const three2 = {
prop: '',
};
three2 satisfies T;
export const four2 = {
prop: '',
} as const;
four2 satisfies T;