Skip to content

Commit

Permalink
fix: Also mark some function return types as optional
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Aug 6, 2024
1 parent ef50863 commit 17299bd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/nitrogen/src/syntax/createType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export function createType(type: TSMorphType, isOptional: boolean): Type {
// It's a function!
const callSignature = getFunctionCallSignature(type)
const funcReturnType = callSignature.getReturnType()
const returnType = createType(funcReturnType, false)
const returnType = createType(funcReturnType, funcReturnType.isNullable())
const parameters = callSignature.getParameters().map((p) => {
const declaration = p.getValueDeclarationOrThrow()
const parameterType = p.getTypeAtLocation(declaration)
Expand Down
6 changes: 5 additions & 1 deletion packages/nitrogen/src/syntax/getInterfaceProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ export function getInterfaceProperties(
return interfaceType.getProperties().map((prop) => {
const declaration = prop.getValueDeclarationOrThrow()
const propType = prop.getTypeAtLocation(declaration)
const refType = createNamedType(prop.getName(), propType, prop.isOptional())
const refType = createNamedType(
prop.getName(),
propType,
prop.isOptional() || propType.isNullable()
)
return refType
})
}

0 comments on commit 17299bd

Please sign in to comment.