Using `satisfies` on a self-referencing object causes `any` - TS 4.9.2-RC
See original GitHub issueBug Report
š Search Terms
š Version & Regression Information
Version 4.9.2-rc
š» Code
interface Items {
id: 'a' | 'b';
condition: () => boolean;
}
// 'items' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.ts (7022)
const items = {
foo: {
id: 'a',
condition: () => true
},
bar: {
id: 'b',
condition: () => items.foo.id === 'a'
},
} satisfies Record<string, Items>;
š Actual behavior
items
implicitly has type any
.
š Expected behavior
items
should be checked with the Items
interface and still have typesafe keys.
Issue Analytics
- State:
- Created 10 months ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Documentation - TypeScript 4.9
JavaScript's in operator can check whether a property exists on an object. Previously, TypeScript allowed us to narrow away any types that don't...
Read more >Self-referencing a mapped type in TypeScript - Stack Overflow
I'm open to changing the source Lang<T> type, as long as it still allows me to express node types and fold / reduce...
Read more >Self referencing object literal in JavaScript - clubmate.fi
Sometimes it is desirable to allow access to a property that returns a dynamically computed value, or you may want to reflect the...
Read more >Ungrounded Self-Reference: The Solution to the Liar Paradox?
self -reference can also satisfy criterion 1 by defusing all forms of the Liar. Paradox. In Ā§6 I argue that ungrounded self-reference satisfies...
Read more >Self-Reference - Stanford Encyclopedia of Philosophy
The philosophical interest in self-reference is to a large extent centered ... \(Q(y)\) is the universal predicate true of any object.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I feel like TS needs better error messages.
The error textā¦
ā¦implies that simply referencing yourself is sufficient cause for error, but in reality sometimes itās allowed (intentionally, even). Iām starting to see why people complain so much about TS being inconsistentācontext matters, but the error messages tend to speak in absolutes, making any difference in error-producing behavior look like a bugā¦
I guess if I had to put my finger on it, itās the difference between āyouāre not allowed to do thisā vs. āI canāt resolve this and hereās the complication I ran into while tryingā, and itās easy to read some errors as implying the former when itās really the latter.
Iām not sure if thereās a way for us to avoid pulling on the type of
types
here before itās been initialized, but since you can observe the same thing with a āfakeā version ofsatisfies
in older versions of TypeScript, I might be tempted to say that this is an expected design limitation.That said, maybe we could do something a little different here. We could possibly defer all comparisons for
satisifes
until after all deferred function bodies have been checked as well. So basicallysatisfies
does nothing except for provide a contextual type at first, and then is checked after everything else.