Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Ambient type information #5276

Closed
wants to merge 1 commit into from

Conversation

mike-north
Copy link
Contributor

This is a far-from-complete initial pass at adding ambient type information for ember-data.

Currently, in order to resolve model names to types in places like...

class AllPostsRoute extends Route {
  
  model(): Promise<ArrayProxy<BlogPost>> {
    return this.store.findAll('blog-post');
  }

}

class BlogPost extends DS.Model {
 
 author: ComputedProperty<User> = hasMany('user')

}

Users have to create a little RecordTypeMap mapping in their project (see below). Additional transforms for attr types can be specified here as well via a TransformsMap mapping, and the ambient types in this branch will take them into account when validating constraints.

app/ember-data.custom.d.ts
declare module 'ember-data/types' {
  import { BlogPost } from 'my-app/models/blog-post';
  import { User } from 'mikenorth/models/user';

  interface RecordTypeMap {
    user: User;
    'blog-post': BlogPost;
  }
  interface TransformsMap {
    csv: string[];
  }
}

I'll periodically update this as I flesh things out. If users wish to try these in their project right now, just create a file called app/ember-data.d.ts identical to the index.d.ts from this branch.

@runspired
Copy link
Contributor

@mike-north is there value in rebooting this PR? Or have other projects superseded it?

@mike-north
Copy link
Contributor Author

@runspired we can shut this down. Type information lives here now

source: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/ember-data
pkg: https://www.npmjs.com/package/@types/ember-data

@mike-north mike-north closed this Oct 5, 2018
@mike-north mike-north deleted the typescript branch October 5, 2018 05:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants