打字稿文件中的JSON数据有误。
我试图在Angular中创建一个执行git-search操作的API。最初我拥有JSON数据,但后来我将所有数据值更改为数据类型,即将2323更改为数字“ https://www.google.com”以字符串,依此类推,但出现了 TS2314 错误。
我已经将双引号固定为单引号,但这很简单。 我也用<>;
export interface GitSearch {
'total_count': number;
'incomplete_results': boolean;
'items': Array<
{
'id': number,
'node_id': string,
'name': string,
'full_name': string,
'private': boolean,
'owner': {
'login': string,
'id': number,
'node_id': string,
'avatar_url': string,
'gravatar_id': string,
'url': string,
'html_url': string,
'followers_url': string,
'following_url': string,
'gists_url': string,
'starred_url': string,
'subscriptions_url': string,
'organizations_url': string,
'repos_url': string,
'events_url': string,
'received_events_url': string,
'type': string,
'site_admin': boolean
},
'html_url': string,
'description': string,
'fork': boolean,
'url': string,
'forks_url': string,
'keys_url': string,
'collaborators_url': string,
'teams_url': string,
'hooks_url': string,
'issue_events_url': string,
'events_url': string,
'assignees_url': string,
'branches_url': string,
'tags_url': string,
'blobs_url': string,
'git_tags_url': string,
'git_refs_url': string,
'trees_url': string,
'statuses_url': string,
'languages_url': string,
'stargazers_url': string,
'contributors_url': string,
'subscribers_url': string,
'subscription_url': string,
'commits_url': string,
'git_commits_url': string,
'comments_url': string,
'issue_comment_url': string,
'contents_url': string,
'compare_url': string,
'merges_url': string,
'archive_url': string,
'downloads_url': string,
'issues_url': string,
'pulls_url': string,
'milestones_url': string,
'notifications_url': string,
'labels_url': string,
'releases_url': string,
'deployments_url': string,
'created_at': string,
'updated_at': string,
'pushed_at': string,
'git_url': string,
'ssh_url': string,
'clone_url': string,
'svn_url': string,
'homepage': string,
'size': number,
'stargazers_count': number,
'watchers_count': number,
'language': null,
'has_issues': boolean,
'has_projects': boolean,
'has_downloads': boolean,
'has_wiki': boolean,
'has_pages': boolean,
'forks_count': number,
'mirror_url': null,
'archived': boolean,
'disabled': boolean,
'open_issues_count': number,
'license': {
'key': string,
'name': string,
'spdx_id': string,
'url': string,
'node_id': string
},
'forks': number,
'open_issues': number,
'watchers': number,
'default_branch': string,
'score': number
},
{
'id': number,
'node_id': string,
'name': string,
'full_name': string,
'private': boolean,
'owner': {
'login': string,
'id': number,
'node_id': string,
'avatar_url': string,
'gravatar_id': string,
'url': string,
'html_url': string,
'followers_url': string,
'following_url': string,
'gists_url': string,
'starred_url': string,
'subscriptions_url': string,
'organizations_url': string,
'repos_url': string,
'events_url': string,
'received_events_url': string,
'type': string,
'site_admin': boolean
},
'html_url': string,
'description': string,
'fork': boolean,
'url': string,
'forks_url': string,
'keys_url': string,
'collaborators_url': string,
'teams_url': string,
'hooks_url': string,
'issue_events_url': string,
'events_url': string,
'assignees_url': string,
'branches_url': string,
'tags_url': string,
'blobs_url': string,
'git_tags_url': string,
'git_refs_url': string,
'trees_url': string,
'statuses_url': string,
'languages_url': string,
'stargazers_url': string,
'contributors_url': string,
'subscribers_url': string,
'subscription_url': string,
'commits_url': string,
'git_commits_url': string,
'comments_url': string,
'issue_comment_url': string,
'contents_url': string,
'compare_url': string,
'merges_url': string,
'archive_url': string,
'downloads_url': string,
'issues_url': string,
'pulls_url': string,
'milestones_url': string,
'notifications_url': string,
'labels_url': string,
'releases_url': string,
'deployments_url': string,
'created_at': string,
'updated_at': string,
'pushed_at': string,
'git_url': string,
'ssh_url': string,
'clone_url': string,
'svn_url': string,
'homepage': string,
'size': number,
'stargazers_count': number,
'watchers_count': number,
'language': string,
'has_issues': boolean,
'has_projects': boolean,
'has_downloads': boolean,
'has_wiki': boolean,
'has_pages': boolean,
'forks_count': number,
'mirror_url': null,
'archived': boolean,
'disabled': boolean,
'open_issues_count': number,
'license': {
'key': string,
'name': string,
'spdx_id': string,
'url': string,
'node_id': string
},
'forks': number,
'open_issues': number,
'watchers': number,
'default_branch': string,
'score': number
},
{
'id': number,
'node_id': string,
'name': string,
'full_name': string,
'private': boolean,
'owner': {
'login': string,
'id': number,
'node_id': string,
'avatar_url': string,
'gravatar_id': string,
'url': string,
'html_url': string,
'followers_url': string,
'following_url': string,
'gists_url': string,
'starred_url': string,
'subscriptions_url': string,
'organizations_url': string,
'repos_url': string,
'events_url': string,
'received_events_url': string,
'type': string,
'site_admin': boolean
},
'html_url': string,
'description': string,
'fork': boolean,
'url': string,
'forks_url': string,
'keys_url': string,
'collaborators_url': string,
'teams_url': string,
'hooks_url': string,
'issue_events_url': string,
'events_url': string,
'assignees_url': string,
'branches_url': string,
'tags_url': string,
'blobs_url': string,
'git_tags_url': string,
'git_refs_url': string,
'trees_url': string,
'statuses_url': string,
'languages_url': string,
'stargazers_url': string,
'contributors_url': string,
'subscribers_url': string,
'subscription_url': string,
'commits_url': string,
'git_commits_url': string,
'comments_url': string,
'issue_comment_url': string,
'contents_url': string,
'compare_url': string,
'merges_url': string,
'archive_url': string,
'downloads_url': string,
'issues_url': string,
'pulls_url': string,
'milestones_url': string,
'notifications_url': string,
'labels_url': string,
'releases_url': string,
'deployments_url': string,
'created_at': string,
'updated_at': string,
'pushed_at': string,
'git_url': string,
'ssh_url': string,
'clone_url': string,
'svn_url': string,
'homepage': string,
'size': number,
'stargazers_count': number,
'watchers_count': number,
'language': null,
'has_issues': boolean,
'has_projects': boolean,
'has_downloads': boolean,
'has_wiki': boolean,
'has_pages': boolean,
'forks_count': number,
'mirror_url': null,
'archived': boolean,
'disabled': boolean,
'open_issues_count': number,
'license': null,
'forks': number,
'open_issues': number,
'watchers': number,
'default_branch': string,
'score': number
}
>;
}
我希望上面的输出没有错误。
答案 0 :(得分:0)
我只是将您的代码转换为在打字稿中使用类和接口的正确方法。
export interface GitSearch {
total_count: number;
incomplete_results: boolean;
items: Array<ItemModel>;
}
export class Licence {
key: string;
name: string;
spdx_id: string;
url: string;
node_id: string;
}
export class OwnerModel {
login: string;
id: number;
node_id: string;
avatar_url: string;
gravatar_id: string;
url: string;
html_url: string;
followers_url: string;
following_url: string;
gists_url: string;
starred_url: string;
subscriptions_url: string;
organizations_url: string;
repos_url: string;
events_url: string;
received_events_url: string;
type: string;
site_admin: boolean
}
export class ItemModel {
id: number;
node_id: string;
name: string;
full_name: string
private: boolean;
owner: OwnerModel
html_url: string;
description: string;
fork: boolean;
url: string;
forks_url: string;
keys_url: string;
collaborators_url: string;
teams_url: string;
hooks_url: string;
issue_events_url: string;
events_url: string;
assignees_url: string;
branches_url: string;
tags_url: string;
blobs_url: string;
git_tags_url: string;
git_refs_url: string;
trees_url: string;
statuses_url: string;
languages_url: string;
stargazers_url: string;
contributors_url: string;
subscribers_url: string;
subscription_url: string;
commits_url: string;
git_commits_url: string;
comments_url: string;
issue_comment_url: string;
contents_url: string;
compare_url: string;
merges_url: string;
archive_url: string;
downloads_url: string;
issues_url: string;
pulls_url: string;
milestones_url: string;
notifications_url: string;
labels_url: string;
releases_url: string;
deployments_url: string;
created_at: string;
updated_at: string;
pushed_at: string;
git_url: string;
ssh_url: string;
clone_url: string;
svn_url: string;
homepage: string;
size: number;
stargazers_count: number;
watchers_count: number;
language: null;
has_issues: boolean;
has_projects: boolean;
has_downloads: boolean;
has_wiki: boolean;
has_pages: boolean;
forks_count: number;
mirror_url: null;
archived: boolean;
disabled: boolean;
open_issues_count: number;
license: Licence;
forks: number;
open_issues: number;
watchers: number;
default_branch: string;
score: number;
}