Created
March 24, 2017 10:21
-
-
Save blaugold/75e4f4d64c5edd53b6504dc042255f5f to your computer and use it in GitHub Desktop.
angular-firebase
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { FirebaseDatabase } from '@blaugold/angular-firebase' | |
import 'rxjs/add/operator/map' | |
/** | |
* This example demonstrates the type checking ability when the database is used with a schema. | |
* Open this file with an ide like VS Code or WebStorm and you should see error highlighting. | |
*/ | |
interface DBSchema { | |
todoLists: { | |
[listId: string]: { | |
name: string | |
todoItems: { | |
[itemId: string]: { | |
title: string | |
checked: boolean | |
} | |
} | |
} | |
} | |
} | |
let db: FirebaseDatabase<DBSchema> | |
// Should compile. | |
db.ref().child('todoLists').child('1').child('todoItems') | |
db.ref().child('todoLists').child('1').child('name').onValue().val() | |
.map((name: string /* Compiles since `name`has type string. */) => {}) | |
// Should not compile. | |
db.ref().child('todoLists').child('1').child('todoItemz') // todoItemz should be todoItems. | |
db.ref().child('todoLists').child('1').child('name').onValue().val() | |
.map((name: number /* Fails since `name` has type string. */) => {}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment