Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4829

Typescript and model class definition

$
0
0

@flashios09 wrote:

Hi,

I’m using typescript with ember and want to check if a passed param is a model record instead of using any , something like this:

import Ember from 'ember';
import { action } from '@ember-decorators/object';

const {
  Controller
} = Ember;

// i tried this but ts will tell me that i have to add `destroyRecord` also:
// `app/controllers/libraries/index.ts(21,15): error TS2339: Property 'destroyRecord' does not exist on type 'Library'.`
// i want to have something that contains the model defintion to extend from it :)
type Library = {
  name: string,
  address: string,
  phone: string,
  // i don't like to do something like this
  destroyRecord: any,
  save: any,
  anotherUsedMethod: any
}

export default class LibrariesIndexController extends Controller {

  @action
  // i don't want to use `any` here
  // i want to do something like this `library: Library`
  deleteLibrary(library: Library) {
    let confirmation = confirm("Are you sure ?");

    if (confirmation) {
      library.destroyRecord();
    }
  }
}

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4829

Trending Articles