Skip to content

Instantly share code, notes, and snippets.

@blaugold
Created March 24, 2017 10:21
Show Gist options
  • Save blaugold/75e4f4d64c5edd53b6504dc042255f5f to your computer and use it in GitHub Desktop.
Save blaugold/75e4f4d64c5edd53b6504dc042255f5f to your computer and use it in GitHub Desktop.
angular-firebase
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