Skip to content

Documentation / @ember-data/model / migration-support / WithLegacy

ts
type WithLegacy<T> = T & LegacyModeRecord<T>;

Defined in: packages/model/src/migration-support.ts:179

A Type utility that enables quickly adding type information for the fields defined by import { withDefaults } from '@ember-data/model/migration-support'.

Example:

ts
import { withDefaults, WithLegacy } from '@ember-data/model/migration-support';
import { Type } from '@warp-drive/core-types/symbols';
import type { HasMany } from '@ember-data/model';

export const UserSchema = withDefaults({
  type: 'user',
  fields: [
    { name: 'firstName', kind: 'attribute' },
    { name: 'lastName', kind: 'attribute' },
    { name: 'age', kind: 'attribute' },
    { name: 'friends',
      kind: 'hasMany',
      type: 'user',
      options: { inverse: 'friends', async: false }
    },
    { name: 'bestFriend',
      kind: 'belongsTo',
      type: 'user',
      options: { inverse: null, async: false }
    },
  ],
});

export type User = WithLegacy<{
  firstName: string;
  lastName: string;
  age: number;
  friends: HasMany<User>;
  bestFriend: User | null;
  [Type]: 'user';
}>

Type Parameters

T

T extends TypedRecordInstance

Released under the MIT License.