Skip to content

Instantly share code, notes, and snippets.

@decadef20
Last active April 16, 2020 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save decadef20/295f4b081f7dfb92010e16b1b7e92f13 to your computer and use it in GitHub Desktop.
Save decadef20/295f4b081f7dfb92010e16b1b7e92f13 to your computer and use it in GitHub Desktop.
// how to add ts interface by babel-types
const interfaces = path.insertAfter(
t.tSInterfaceDeclaration(
t.identifier('State'),
null,
null,
t.tsInterfaceBody(
[ t.tsPropertySignature(t.stringLiteral('test'), t.tsTypeAnnotation(t.TSLiteralType(t.stringLiteral('string')))) ]
)
)
)
// how to add ts type by babel-types
const types = t.typeAlias(
t.identifier("State"),
t.typeParameterDeclaration(
[]
// [t.TypeParameter(t.typeAnnotation(t.stringLiteralTypeAnnotation('string')), t.stringLiteralTypeAnnotation('string') , t.variance('plus'))]
),
t.objectTypeAnnotation(
[
t.ObjectTypeProperty(t.identifier('test'), t.stringLiteralTypeAnnotation('string')) ,
t.ObjectTypeProperty(t.identifier('aaa'), t.stringLiteralTypeAnnotation('string'))
]
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment