Skip to content

Instantly share code, notes, and snippets.

@decadef20
Last active April 16, 2020 13:30
Show Gist options
  • Save decadef20/295f4b081f7dfb92010e16b1b7e92f13 to your computer and use it in GitHub Desktop.
Save decadef20/295f4b081f7dfb92010e16b1b7e92f13 to your computer and use it in GitHub Desktop.

Revisions

  1. decadef20 revised this gist Apr 16, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions babel.code.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    // append interface
    // how to add ts interface by babel-types
    const interfaces = path.insertAfter(
    t.tSInterfaceDeclaration(
    t.identifier('State'),
    @@ -11,7 +11,7 @@ const interfaces = path.insertAfter(
    )


    // append type
    // how to add ts type by babel-types
    const types = t.typeAlias(
    t.identifier("State"),
    t.typeParameterDeclaration(
  2. decadef20 created this gist Apr 16, 2020.
    27 changes: 27 additions & 0 deletions babel.code.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    // append interface
    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')))) ]
    )
    )
    )


    // append type
    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'))
    ]
    )
    )