错误 TS2304:找不到名称"IToken响应"



我得到以下错误:

错误TS2304: Cannot find name 'ITokenResponse'.

我试图按照另一个StackOverflow答案的建议导入,但它给出了这个错误:

错误TS2306: File 'C:/Repository/MAngular/src/app/interfaceModals/ItokenResponse。t '不是一个模块。

我该如何解决这个问题?代码如下,我正在使用Angular12。谢谢你! !

import { Inject, Injectable, PLATFORM_ID } from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {map, tap} from 'rxjs/operators' ;
import { isPlatformBrowser } from '@angular/common';

@Injectable({
providedIn: 'root'
})
export class AuthenticationService {
client_id: string = "Manage";
authKey: string ="auth";
roleKey: string="role";
constructor(private http: HttpClient, @Inject(PLATFORM_ID) private platformId:any) { }
login(username: string, password: string, userRole: string){
var data ={
username: username,
password: password,
client_id: this.client_id,
grant_type: "password",
role_name: userRole
};
this.http.post<ITokenResponse>('url', data)
.pipe(map( tkDetails => {
let checkIfTokenConditions =  tkDetails && tkDetails.token;
//the above statement is lambda expresion. it checks if the 
if(checkIfTokenConditions){
this.setAuth(tkDetails);
this.setRole(tkDetails.role_name);
}
return tkDetails;
}))

}

要跨不同的文件共享类、接口、函数或变量(也称为全局作用域),您需要export关键字。

ItokenResponse.ts

export interface ITokenResponse {
token: string;
expiration: number;
refresh_token: string;
role_name: string;
}

接下来,您需要一个import来使用从不同模块导出的变量、函数、类和接口。

authentication-service.ts

import { ITokenResponse } from 'src/app/interfaceModals/ItokenResponse';
export class AuthenticationService {
...
}

最新更新