Reputation: 11
I am trying to use Typescript for my firebase project and i am getting the following errors.
error TS2693: 'Note' only refers to a type, but is being used as a value here.
I used the following code
interface Note {
image: string;
name: string;
pdf: string;
}
const itemname = Note.name;
But that doesn't seem to work
here is the imports
import {
AngularFirestore,
AngularFirestoreCollection,
AngularFirestoreDocument,
} from '@angular/fire/firestore';
import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import 'rxjs/add/operator/map';
here is the other part
export class Advance11Component implements OnInit {
notesCollection: AngularFirestoreCollection<Note>;
notes: Observable<Note[]>;
constructor(private afs: AngularFirestore) {}
ngOnInit(): void {
this.notesCollection = this.afs
.collection('class11AdvancedTheory')
.doc(itemname)
.collection(itemname, (ref) => {
return ref;
});
this.notes = this.notesCollection.valueChanges();
}
}
Upvotes: 0
Views: 13897
Reputation: 7206
An interface
(or type
) can tell you the shape of something.
// A `tree` has a number of `branches`.
interface Tree {
branches: number
}
An instance (e.g. const x = ...
) assigns a specific value that can be reference at runtime.
// This `tree` has 34 `branches`.
const myTree: Tree = { branches: 34 }
You cannot mix these two during assignments. Taking your example, you would ask "How many branches
does myTreeBranches
have?" and it would say "typeof Tree.branches
is number
", information that is not useful or supported in JavaScript.
// Doesn't work
const myTreeBranches = Tree.branches // typeof `Tree.branches` is `number`.
You probably want one of these:
interface Tree {
branches: number
}
type TreeBranches = Tree['branches'] // extract an interface property
const myTree: Tree = { branches: 34 } // create an instance of `Tree`
const myTreeBranches: Tree['branches'] = 34 // create variable that could be assigned to
// an instance of `Tree`
Upvotes: 2