【问题标题】:Code completion for Firebase in VS code?VS 代码中 Firebase 的代码完成?
【发布时间】:2017-10-31 15:36:50
【问题描述】:

开启this video Typescript 用于代码完成。 我按照here 的说明操作,让 Typescript 与 Hello World 示例一起工作。我不知道接下来要做什么才能为 Firebase 完成代码。

如何在 VS Code 中获得 Firebase 的代码补全?

更新 1

我在 VS 代码终端中使用以下命令创建了我的 Firebase 项目:firebase initfirebase init functions。所以我还希望代码完成在我必须创建的 functions/index.ts 文件中工作,只是说。

然后我做了npm init 并按照建议:

npm install --save-dev @types/firebase

现在在项目的根目录中,我有 node_module 目录,其中只有 @types/firebase 作为内容和这个 package.json 文件:

{
  "name": "My Project",
  "version": "1.0.0",
  "description": "Does something",
  "main": "index.js",
  "dependencies": {},
  "devDependencies": {
    "@types/firebase": "^2.4.31"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Somebody",
  "license": "ISC"
}

我还创建了一个index.ts 文件进行测试,但是当我输入firebase. 时没有代码完成。完成代码的下一步是什么?

更新 2

.vscode/tasks.json:

{
  // See https://go.microsoft.com/fwlink/?LinkId=733558
  // for the documentation about the tasks.json format
  "version": "0.1.0",
  "command": "tsc",
  "isShellCommand": true,
  "args": ["-w", "-p", "."],
  "showOutput": "silent",
  "isBackground": true,
  "problemMatcher": "$tsc-watch"
}

tsconfig.json:

{
    "compilerOptions": {
        "target": "es5", 
        "sourceMap": true
    }    
}

仍然没有代码完成!

更新 3

functions/index.ts文件的开头我有兴趣看代码补全:

import * as firebase from 'firebase';
var functions = require('firebase-functions');

import * as firebase from 'firebase' 部分来自this video,我在其中看到代码完成工作。我还希望代码完成在 public/app.ts 客户端文件中工作。

【问题讨论】:

    标签: javascript typescript firebase visual-studio-code intellisense


    【解决方案1】:

    我在functions/index.ts的开头使用

    import functions = require('firebase-functions'); import admin = require('firebase-admin');

    它有效。

    【讨论】:

    • 我从示例中得到的代码有 const 函数 = require(...)。将 const 更改为 import 对我有用。谢谢!
    • 在类型脚本中它工作得很好..但我坚持在 javascript 中没有智能感知
    【解决方案2】:

    请安装 firebase typings 以完成 firebase 代码

           npm install --save-dev @types/firebase
    

    【讨论】:

    • 我根据您的建议更新了我的问题。我仍然缺少一些东西,因为还没有代码完成。
    • 你也必须这样做tsc init
    • 使用tsc init 我得到这个错误:error TS6053: File 'init.ts' not found。最后,我创建了一个index.ts(因为这是我最需要代码完成的地方)文件并这样做了:tsc .\functions\index.ts。还是没有运气。
    • 我的意思是说你需要从 tsc init 创建的 tsconfig.json
    • 我创建了文件。更新了问题。仍然没有代码完成。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-20
    • 2012-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-01
    • 2011-04-20
    相关资源
    最近更新 更多