Package Exports
- @creditkarma/thrift-typescript
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@creditkarma/thrift-typescript) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Thrift TypeScript
Generate TypeScript from Thrift IDL files.
Installation
npm install --save @creditkarma/thrift-typescriptUsage
Thrift TypeScript provides both a JavaScript and a command line API.
Given the following files
thrift/simple.thrift
struct MyStruct {
1: required int id,
2: required bool field1,
# 3: required string field,
4: required i16 field,
}You can generate TypeScript via the command line:
thrift-typescript --rootDir . --sourceDir thrift --outDir codegen simple.thriftThe available options are:
- --rootDir: This is used to resolve out and source directories. Defaults to current directory.
- --outDir: The directory to save generated files to. Will be created if it doesn't exist. Defaults to 'codegen'.
- --sourceDir: The directory to search for source Thrift files. Defaults to 'thrift'.
All other fields are assumed to be source files.
You can gen code from more than one Thrift file:
thrift-typescript one.thrift two.thrift three.thriftYou can also generate files using the JavaScript API:
import { generate } from '@creditkarma/thrift-typescript'
// Generates TypeScript and saves to given outDir
generate({
rootDir: '.',
sourceDir: 'thirft',
outDir: 'codegen',
files: [
'simple.thrift'
]
})You can generate TypeScript from a string of Thrift without saving to file.
Note: This method of code generation does not support includes. The Thrift generator must be able to resolve all identifiers which it can't do without a description of the file structure.
import { readFileSync } from 'fs'
import { make } from '@creditkarma/thrift-typescript'
const rawThrift: string = readFileSync('./thrift/simple.thrift', 'utf-8')
const generatedCode: string = make(rawThrift)Development
Install dependencies with
npm installBuild
npm run buildRun test in watch mode
npm run test:watchContributing
For more information about contributing new features and bug fixes, see our Contribution Guidelines. External contributors must sign Contributor License Agreement (CLA)
License
This project is licensed under Apache License Version 2.0