我试图在我的消防基础项目中使用打字本,并得到以下错误。
error TS2693: 'Note' only refers to a type, but is being used as a value here.我使用了以下代码
interface Note {
image: string;
name: string;
pdf: string;
}
const itemname = Note.name;但这似乎行不通
这是进口品
import {
AngularFirestore,
AngularFirestoreCollection,
AngularFirestoreDocument,
} from '@angular/fire/firestore';
import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import 'rxjs/add/operator/map';这是另一部分
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();
}
}发布于 2021-05-27 15:52:14
interface (或type)可以告诉你某事的形状。
// A `tree` has a number of `branches`.
interface Tree {
branches: number
}实例(例如const x = ...)分配一个可以在运行时引用的特定值。
// This `tree` has 34 `branches`.
const myTree: Tree = { branches: 34 }在作业期间,你不能把这两者混合在一起。以您为例,您会问:“branches有多少myTreeBranches?”它会说"typeof Tree.branches is number",这是在JavaScript中不有用或不受支持的信息。
// Doesn't work
const myTreeBranches = Tree.branches // typeof `Tree.branches` is `number`. 你可能想要其中之一:
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`https://stackoverflow.com/questions/67725120
复制相似问题