typescript 带有打字稿的 Firebase 3.0
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37320024/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Firebase 3.0 with typescript
提问by Mufaddal Gulshan
I am trying to develop a web app with angular2 and firebase 3.0 authentication following the guidelines given by google. However all the guides for web have javascript examples.
我正在尝试按照谷歌给出的指南开发一个带有 angular2 和 firebase 3.0 身份验证的网络应用程序。然而,所有的网络指南都有 javascript 示例。
I added below lines in my index.html
我在 index.html 中添加了以下几行
<script src="https://www.gstatic.com/firebasejs/live/3.0/firebase.js"></script>
var config = {
apiKey: "AIzaSyCSfBMvAdEDpcm-z6gWp2XXXXXXXXXXXXX",
authDomain: "fototrans-calculator.firebaseapp.com",
databaseURL: "https://fototrans-calculator.firebaseio.com",
storageBucket: "fototrans-calculator.appspot.com",
};
firebase.initializeApp(config);
But when i try to use
但是当我尝试使用
rootRef = firebase.database.ref();
I get an error on 'firebase' saying
我在“firebase”上遇到错误说
[ts] Cannot find name 'firebase'.
Now I remember that I had installed firebase using typings for the previous version of Firebase. Do we have any such thing again for the new version of Firebase? Please guide.
现在我记得我已经使用之前版本的 Firebase 的类型安装了 firebase。对于新版本的 Firebase,我们还有这样的事情吗?请指导。
Thanks in advance
提前致谢
回答by urish
As of Firebase 3.2.1, the typings are included as part of the official NPM package:
从 Firebase 3.2.1 开始,类型包含在官方 NPM 包中:
https://firebase.google.com/support/release-notes/js#wzxhzdk4version_321_-_july_26_2016wzxhzdk5
https://firebase.google.com/support/release-notes/js#wzxhzdk4version_321_-_july_26_2016wzxhzdk5
回答by Alex Weber
You can work around this by doing declare var firebase: any;
你可以通过做来解决这个问题 declare var firebase: any;
回答by Rick
There is a type definition file available at https://github.com/suhdev/firebase-3-typescript
https://github.com/suhdev/firebase-3-typescript有一个类型定义文件
I have submitted a pull requestthat will hopefully solve the issue you are describing.
我已经提交了一个拉取请求,希望能解决您所描述的问题。
回答by Pete
You can use the Typings definition file provided in the AngularFire2 GitHub repository (located here):
您可以使用 AngularFire2 GitHub 存储库(位于此处)中提供的 Typings 定义文件:
Include the following in your typings.json
file:
在您的typings.json
文件中包含以下内容:
{
"ambientDependencies": {
"firebase": "github:angular/angularfire2/manual_typings/firebase3/firebase3.d.ts#2c9ab3117eeb804e8e4996461eddcf32efa54a56"
}
}
Note that the value here is simply the path to the file on GitHub followed by the relevant commit hash. The hash in the example is master
at time of writing so you may wish to update to the latest commit.
请注意,此处的值只是 GitHub 上文件的路径,后跟相关的提交哈希。示例中的哈希值是master
在撰写本文时,因此您可能希望更新到最新提交。
Next you can run node_modules/.bin/typings install
and Typings will apply the latest changes from your typings.json
file.
接下来您可以运行node_modules/.bin/typings install
,Typings 将应用您typings.json
文件中的最新更改。
回答by Eusthace
You can try to use it this one: https://github.com/angular/angularfire2/tree/master/manual_typings/firebase3
您可以尝试使用它:https: //github.com/angular/angularfire2/tree/master/manual_typings/firebase3
And to get it to work you need to add it to your tsconfig.json:
为了让它工作,你需要将它添加到你的 tsconfig.json 中:
"filesGlob": [
"**/*.ts",
"!node_modules/**/*",
"firebase3.d.ts"
],
And copy the file to the same folder as your tsconfig.json.
并将文件复制到与 tsconfig.json 相同的文件夹中。