ts-morph icon indicating copy to clipboard operation
ts-morph copied to clipboard

Property `getAssertClause` does not exist on type `ImportDeclaration`

Open bennycode opened this issue 1 year ago • 2 comments

Describe the bug

Version: 21.0.1

To Reproduce

When upgrading from ts-morph v20 to v21 the getAssertClause is no longer available on an ImportDeclaration:

import {Project, SyntaxKind} from 'ts-morph';

const project = new Project();

project.getSourceFiles().forEach(sourceFile => {
  sourceFile.getImportDeclarations().forEach(importDeclaration => {
    importDeclaration.getDescendantsOfKind(SyntaxKind.StringLiteral).forEach(() => {
      // It fails here:
      console.log(importDeclaration.getAssertClause());
    });
  });
});

Expected behavior

I wish to call this method but I couldn't find any hint in the release notes where to find it now: https://github.com/dsherret/ts-morph/releases

bennycode avatar Jan 07 '24 13:01 bennycode

@dsherret can you give me a hint what I can use instead of getAssertClause()?

Edit: Telling from this change I have to call getAttributes() now? I guess this is because TS 5.3 updated to the import attributes proposal (source).

bennycode avatar Apr 24 '24 13:04 bennycode

Ok, I am using getAttributes() now but it would be nice to know how to find assert clauses in legacy code. I would need it to write a codemod that can convert the old assert {type: 'json'} syntax into with {type: 'json'}.

bennycode avatar Apr 30 '24 09:04 bennycode