-
项目:https://github.com/NonceGeek/scaffold-move/tree/main/scaffold-sui 红线部分在 yarn build 的时候就会没法通过,提示 data 字段不存在对应的类型 'string' 中,但是数据类型是 Union 的,应该是符合下面报错信息的第三个类型 报错信息: $ yarn build
yarn run v1.22.19
$ next build
info - Loaded env from /Users/qiwihui/Development/smart/scaffold-move/scaffold-sui/.env.local
info - Linting and checking validity of types ..Failed to compile.
./src/pages/index.tsx:80:26
Type error: Property 'data' does not exist on type 'string | { digest: string; objectId: string; version: number; } | { data: { type: string; fields: Record<string, any>; dataType: "moveObject"; has_public_transfer?: boolean | undefined; } | { ...; }; owner: "Immutable" | ... 2 more ... | { ...; }; previousTransaction: string; storageRebate: number; reference: { ...;...'.
Property 'data' does not exist on type 'string'.
78 | const nfts = nftObjects.filter(item => item.status === "Exists").map(item => {
79 | return {
> 80 | id: item.details.data.fields.id.id,
| ^
81 | name: item.details.data.fields.name,
82 | url: item.details.data.fields.url,
83 | description: item.details.data.fields.description,
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. 对应的 object 请求和返回数据: 请求: {
"jsonrpc": "2.0",
"id": 1,
"method": "sui_getObject",
"params":[
"0x7c8abfa838132eeb1470801eb0e2599fdd464923"
]
} 返回 {
"jsonrpc": "2.0",
"result": {
"status": "Exists",
"details": {
"data": {
"dataType": "moveObject",
"type": "0x2::devnet_nft::DevNetNFT",
"has_public_transfer": true,
"fields": {
"description": "123",
"id": {
"id": "0x7c8abfa838132eeb1470801eb0e2599fdd464923"
},
"name": "abc",
"url": "https://user-images.githubusercontent.com/76067158/166136286-c60fe70e-b982-4813-932a-0414d0f55cfb.png"
}
},
"owner": {
"AddressOwner": "0x659f89084673bf4a993cdea89a94dabf93a2ddb4"
},
"previousTransaction": "9MV6cYgXgABaEu4tsD7ukV7ywT7rhFt1NJibq3yVtVmz",
"storageRebate": 24,
"reference": {
"objectId": "0x7c8abfa838132eeb1470801eb0e2599fdd464923",
"version": 1115,
"digest": "3aPXRK+g7B6700tzFZR/BGywEnEbMzpjpW6WK8fFYkc="
}
}
},
"id": 1
} |
Beta Was this translation helpful? Give feedback.
Answered by
leo-web3
Jan 20, 2023
Replies: 1 comment
-
根据返回值 定义 interface 接口 interface ObjectBatch {
details: {
data: {
dataType: string,
type: string,
has_public_transfer: boolean,
fields: {
description: string,
id: {
id: string
},
name: string,
url: string
}
},
owner: {
AddressOwner: string
},
previousTransaction: string,
storageRebate: number,
reference: {
objectId: string,
version: number,
digest: string
}
}
}; 用法 const nfts = nftObjects.filter(item => item.status === "Exists").map((item: ObjectBatch)=> {
return {
id: item.details.data.fields.id.id,
name: item.details.data.fields.name,
url: item.details.data.fields.url,
description: item.details.data.fields.description,
......
}
}) 注意,不是绝对通用,需要根据返回字段来个性化定义, 如果非大型项目 非必要使用 或者 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
qiwihui
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
根据返回值 定义 interface 接口
用法