Entity.ModelOf<Market<V, Asset<V>, Asset<V>, 'spot'>> produces an empty type with NO fields at all.
- Full Entity.ModelFrom machinery
- Simple test cases
- Result: COMPILES SUCCESSFULLY ✓
- Shows Entity.ModelFrom works in isolation
- Tests union discriminant access
- Progressive complexity scenarios
- Result: COMPILES SUCCESSFULLY ✓
- Shows union types work in isolation
- Complete real-world types from codebase
- Result: REPRODUCES THE BUG ✗
- All fields missing from Model
When TypeScript processes:
Market.Model<V, Asset<V>, Asset<V>, 'spot'>
// which expands to:
Omit<Entity.ModelOf<Market<V, Asset<V>, Asset<V>, 'spot'>>, 'lastPrice'>The resulting type has ZERO fields. Attempts to access ANY field fail:
- ❌
model.id- "Property 'id' does not exist" - ❌
model.symbol- "Property 'symbol' does not exist" - ❌
model.active- "Property 'active' does not exist" - ❌
model.type- "Property 'type' does not exist"
Yet the Market entity clearly declares all these fields:
class Market<V, B, Q, T> extends Entity<Market<V, B, Q, T>, V> {
readonly id!: string;
readonly symbol!: string;
readonly type!: T;
readonly active!: boolean;
readonly venue!: V;
readonly base: B;
readonly quote: Q;
}Check these exported types to identify the break point:
IsSpotModelNever- Is the entire Model type resolving tonever?AreSpotKeysNever- Are the keys being computed asnever?MarketSpotKeys- What doesEntity.ModelFrom.Keys<>return?AreMarketSpotKeysNever- Are the Keys helper returningnever?MarketSpotMethodKeys- Which fields are being excluded as methods?MarketSpotComponentKeys- Which fields are being excluded as components?
When all fields vanish, the Keys computation is likely returning never because:
-
Distributive Conditionals on Unresolved Generics
E[K] extends Entity<any, any>check runs while generics are unfixed- TypeScript pessimistically returns
neverfor each key
-
Key Remapping with
asClause Running Too Early- The mapped type filters run before TypeScript fully resolves generic constraints
- Each key gets remapped to
never, resulting in empty object
-
Component/Entity Detection Failing
- The check
Self[K] extends Component<any> ? (Self[K] extends Entity<any, any> ? never : K) : never - Might be incorrectly classifying fields when generics are involved
- The check
Run the following in TypeScript to see values:
import { IsSpotModelNever, AreSpotKeysNever, MarketSpotKeys, SpotKeys } from './actual-failing-case.js';
// These should be 'NOT_NEVER' and 'KEYS_EXIST'
type Check1 = IsSpotModelNever;
type Check2 = AreSpotKeysNever;
type Check3 = MarketSpotKeys; // Should be 'id' | 'symbol' | 'type' | 'active' | ...If MarketSpotKeys is never, the problem is in the Keys computation.
If SpotKeys is never but MarketSpotKeys has values, the problem is in Build.
If both have values but fields still don't exist, it's likely a TypeScript compiler bug.
Expected:
Entity.ModelOf<Market<V, Asset<V>, Asset<V>, 'spot'>>should produce:{ id: string; symbol: string; type: 'spot'; active: boolean; venueId: string; base: PropertyKey; quote: PropertyKey; }
Actual:
- Produces empty type with zero accessible fields
- All property access fails with "Property '...' does not exist"
npx tsc --noEmit actual-failing-case.tsLook for errors at lines 282-288 showing all field access failures.