英文:
TypeScript variable "implicitly has type 'any' because it does not have a type annotation"
问题
错误:
> 'environment' 因为没有类型注释并且在其自己的初始化程序中直接或间接引用,隐式具有类型 'any'。
代码:
export const environment = {
production: false,
firebaseConfig: {
apiKey: "myKey",
authDomain: "domain",
projectId: "id",
storageBucket: "storageUrl",
messagingSenderId: "59142751602",
appId: "a:b:web:c"
},
};
英文:
Error:
> 'environment' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
Code:
export const environment = {
production: false,
firebaseConfig : {
apiKey: "myKey",
authDomain: "domain",
projectId: "id",
storageBucket: "storageUrl",
messagingSenderId: "59142751602",
appId: "a:b:web:c"
},
};
答案1
得分: 0
只需在tsconfig.json文件中添加以下选项:
"noImplicitAny": false,
禁用此功能并不是一个好主意,但Angular不允许运行项目,它会显示错误。
有关“noImplicitAny”选项的更详细说明,请参阅此处。
英文:
Just add below option in the tsconfig.json file:
"noImplicitAny": false,
Disabling the feature is not good idea but angular not allowed to run the project it shows error.
For more detailed explanation about the "noImplicitAny" option.
答案2
得分: 0
你只需将 any
类型简单地添加到以下代码行中:export const environment: any = { // 在此处填写详细信息 }
。 接受的答案完全有效,但这将禁用整个项目的类型检查,公平地说,使用TypeScript的优势是什么?
英文:
You can simply add any
type to the line export const environment: any = {
. The accepted answer works just fine, however, it will disable type checking across the whole project and being fair, what's the advantage of using Type Script?
// details go here }
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论