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

A condensed reference for the syntax you'll use most often.

// 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: number) => 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 '@scriptrunnerhq/hapi/issues'
import { client } from '@scriptrunnerhq/jira-client'

// Export async function
export default async function () {
  // Your code here
  const issue = await Issues.getByKey('JRA-1')

  if (!issue) {
    throw new Error('JRA-1 not found, or not visible to this script')
  }

  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.