Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler TypeScript Support #470

Merged
merged 2 commits into from
Jun 22, 2023
Merged

Compiler TypeScript Support #470

merged 2 commits into from
Jun 22, 2023

Conversation

sinclairzx81
Copy link
Owner

@sinclairzx81 sinclairzx81 commented Jun 22, 2023

This PR is a subsequent update on #469 to add return type annotations on generated functions.

const T = Type.Object({
  x: Type.Number(),
  y: Type.Number(),
  z: Type.Number(),
})

const C = TypeCompiler.Code(T, [], { language: 'typescript' })

// produces

return function check(value: any): boolean {
  return (
    (typeof value === 'object' && value !== null && !Array.isArray(value)) &&
    (typeof value.x === 'number' && Number.isFinite(value.x)) &&
    (typeof value.y === 'number' && Number.isFinite(value.y)) &&
    (typeof value.z === 'number' && Number.isFinite(value.z))
 )
}

@sinclairzx81 sinclairzx81 merged commit 28d0f33 into master Jun 22, 2023
@sinclairzx81 sinclairzx81 deleted the language branch June 22, 2023 04:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant