The Adaptavist Group LogoDocumentation

TypeScript Syntax Quick Reference

Get a one-page cheatsheet of TypeScript syntax, a ScriptRunner script template, common HAPI operations, and Groovy to TypeScript equivalents.

Essential TypeScript syntax

// Variables
const x = 5 // Cannot reassign
let y = 10 // Can reassign
 
// Template literals
const msg = `Value: ${x}`
 
// Objects
const obj = { key: 'value' }
 
// Arrays
const arr = [1, 2, 3]
 
// Arrow functions
const fn = (param) => param * 2
 
// Conditionals
if (condition) { } else { }
const result = condition ? 'yes' : 'no'
 
// Loops
for (const item of array) { }
for await (const item of asyncIterator) { }
 
// Error handling
try { } catch (error) { } finally { }
 
// Optional chaining
obj?.property?.nested
 
// Nullish coalescing
const value = input ?? 'default'
 
// Equality
x === y  // Use === not ==

ScriptRunner script template

// Import what you need
import * as Issues from '@avst-sr/hapi/issues'
import { client } from '@avst-sr/jira-client'
 
// Export async function
export default async function () {
 // Your code here
 const issue = await Issues.getByKey('JRA-1')
 
  console.log(`Processing: ${issue.key}`)
 
 return issue
}

Common HAPI operations

Tip: See our HAPI documentation for more detail.
 // Create issue
await Issues.create({
  body: {
    fields: {
      project: { key: 'JRA' },
      issuetype: { name: 'Task' },
      summary: 'Summary'
    }
  }
})
 
// Update issue
await Issues.update({
  issueIdOrKey: 'JRA-1',
  body: { fields: { summary: 'New summary' } }
})
 
// Search issues
for await (const issue of Issues.search('project = JRA', {
  fields: ['key', 'summary']
})) {
  console.log(issue.key)
}
 
// Transition issue
await Issues.transition('JRA-1', 'Done')
 
// Link issues
await Issues.linkIssue('JRA-1', 'Blocks', 'JRA-2')
 
// Add comment
await Issues.addComment('JRA-1', { body: 'Comment text' })

Groovy to TypeScript quick lookup

GroovyTypeScript
def x = 5const x = 5
"Hello ${name}"`Hello ${name}`
[1, 2, 3][1, 2, 3]
[key: 'value']{ key: 'value' }
items.each { }for (const item of items) { }
items.collect { it * 2 }items.map(n => n * 2)
items.findAll { it > 5 }items.filter(n => n > 5)
items.sum()items.reduce((a,b) => a+b, 0)
value ?: 'default'value ?? 'default'
x == yx === y
logger.info('msg')console.log('msg')

Search documentation

Start typing to search the docs.