我有一个dotnetcore 20和angular4项目,我正在尝试创建一个userService并让用户访问我的home组件.后端工作正常,但服务没有.问题出在localStorage上.我的错误消息是:
类型'字符串|的参数 null'不能分配给'string'类型的参数.类型'null'不能分配给'string'类型.
和我的userService
import { User } from './../models/users';
import { AppConfig } from './../../app.config';
import { Injectable } from '@angular/core';
import { Http, Headers, RequestOptions, Response } from '@angular/http';
@Injectable()
export class UserService {
constructor(private http: Http, private config: AppConfig) { }
getAll() {
return this.http.get(this.config.apiUrl + '/users', this.jwt()).map((response: Response) => response.json());
}
getById(_id: string) {
return this.http.get(this.config.apiUrl + '/users/' + _id, this.jwt()).map((response: Response) => response.json());
}
create(user: User) {
return this.http.post(this.config.apiUrl + '/users/register', user, …Run Code Online (Sandbox Code Playgroud) 我是 Angular 的新手。
我怎么解决这个问题?
我已经安装Angular CLI: 11.0.7并Node: 12.18.4
错误:
错误:src/app/_services/account.service.ts:19:7 - 错误 TS2345:“OperatorFunction<User, void>”类型的参数不可分配给“OperatorFunction<Object, void>”类型的参数。“对象”类型可分配给很少的其他类型。您是想改用“any”类型吗?“对象”类型缺少“用户”类型中的以下属性:用户名、令牌
Run Code Online (Sandbox Code Playgroud)19 map((response: User) => { ~~~~~~~~~~~~~~~~~~~~~~~~~ 20 const user = response; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ... 24 } ~~~~~~~~~ 25 }) ~~~~~~~~
账户.service.ts
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import {map} from 'rxjs/operators';
import { User } from '../_models/user';
import { ReplaySubject } from 'rxjs';
export class AccountService {
baseUrl = 'https://localhost:5001/api/';
private currentUserSource = new ReplaySubject<User>(1);
currentUser$ = …Run Code Online (Sandbox Code Playgroud) 所以我对 Typescript 和 VueJS 及其所有新功能都很陌生。
一切都按预期工作,但我无法摆脱打字稿错误并同时使用 v-model。
我正在开发一个网络视图,供成员检查和更改其属性。我从 API 获取会员数据并将其存储在 PiniaStore 中。这意味着我有几个需要成员的数字和字符串的输入字段。AFAIK v-model 是输入字段的最佳选择。
Type 'string | number | null | undefined' is not assignable to type 'Nullable<string>'.
Type 'number' is not assignable to type 'Nullable<string>'.
Run Code Online (Sandbox Code Playgroud)
所有关于此错误的 stackoverflow 问题的建议解决方案(例如此一个或此一个)都不适合我的问题 AFAIK。我发现了一个不好的解决方法,我不喜欢在模板块中使用更改事件而不是 v-model,并且在我的脚本中出现相同的错误,但通过忽略它//@ts-ignore。
首先,我真正要求的是如何注释掉 VueJs 模板块中的打字稿错误,已经在这里询问过。
其次,如何解决这个问题而不出现打字稿错误?
看看下面的代码,我遇到了这个错误v-model,不知道如何修复它:
<script setup lang="ts">
import { useMembershipStore } from "@/stores/membership";
const membershipStore = useMembershipStore();
membershipStore.getMembership();
const { membership } = storeToRefs(membershipStore);
function save() {
if …Run Code Online (Sandbox Code Playgroud) I am trying to use this google dynamic form for Angular 11 as is and I get errors.
Here is all the code copied verbatim, obviously it works here but is giving me errors on my dev machine. https://stackblitz.com/edit/angular-sccsnu?file=src%2Fapp%2Fquestion-base.ts
? Compiled successfully.
Error: src/app/_models/question-base.ts:21:5 - error TS2322: Type 'T | undefined' is not assignable to type 'T'.
'T' could be instantiated with an arbitrary type which could be unrelated to 'T | undefined'.
Type 'undefined' is not assignable to type …Run Code Online (Sandbox Code Playgroud) 这是我的hardhat.config.js -
module.exports = {
solidity: "0.8.4",
networks: {
hardhat: {
chainId: 1337
},
mumbai: {
url: "https://rpc-mumbai.matic.today",
accounts: [process.env.pk]
},
// polygon: {
// url: "https://polygon-rpc.com/",
// accounts: [process.env.pk]
// }
}
};
Run Code Online (Sandbox Code Playgroud)
运行 npx Hardhat 测试时出现以下错误:
**Error HH8: There's one or more errors in your config file:
Invalid account: #0 for network: mumbai - Expected string, received undefined**`
Run Code Online (Sandbox Code Playgroud)
我的 Hardhat.config.js 文件似乎有一些错误,但无法找到。我正在使用 Nader Dabit 的 full-stack-web3 教程进行全栈 web3 开发。
typescript ×4
angular ×3
.net-core ×1
asp.net-core ×1
config ×1
hardhat ×1
javascript ×1
solidity ×1
v-model ×1
vue.js ×1
vuejs3 ×1