Skip to content

Commit

Permalink
chore(类型引用): 优化性能
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed Mar 15, 2022
1 parent ae3e327 commit 2ceb20a
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
isObject,
mapKeys,
memoize,
repeat,
run,
traverse,
} from 'vtils'
Expand Down Expand Up @@ -218,14 +217,15 @@ export function jsonSchemaToJSTTJsonSchema(
.replace(/^[a-z]+:/i, ''),
)
const typeAbsolutePathArr = typeAbsolutePath.split('/').filter(Boolean)
const tsType = !typeAbsolutePathArr.length
? typeName
: `${repeat(
'NonNullable<',
typeAbsolutePathArr.length,
)}${typeName}[${typeAbsolutePathArr
.map(v => JSON.stringify(v))
.join(']>[')}]>`

let tsTypeLeft = ''
let tsTypeRight = typeName
for (const key of typeAbsolutePathArr) {
tsTypeLeft += 'NonNullable<'
tsTypeRight += `[${JSON.stringify(key)}]>`
}
const tsType = `${tsTypeLeft}${tsTypeRight}`

jsonSchema.tsType = tsType
}

Expand Down

0 comments on commit 2ceb20a

Please sign in to comment.