dsherret / dsherret/ts-morph

divide typings XXXXStructure into XXXX-Getter-Structure and XXXX-setter-Structure

Open
#668 1 comment 0 reactions 0 assignees View on GitHub
suggestion
Dominant language
TypeScript
Stars
6.2k
Forks
238
Avg merge
2m
Merged PRs (30d)
1

Description

**Is your feature request related to a problem? Please describe.**

I want to modify my code such as this :

```
const node:ImportDeclaration;
const struture:ImportDeclarationStructure = node.getStructure();
// modify structure to structure2
node.setStructure( structure2);
```

here is ImportDeclarationStructure 's typings :
```

interface ImportDeclarationSpecificStructure extends KindedStructure {
defaultImport?: string;
namespaceImport?: string;
namedImports?: (OptionalKind | string | WriterFunction)[] | WriterFunction;
moduleSpecifier: string;
}

```

so when I modify ```namedImports``` , it maybe " WriteFunction , so I cannot write this code :

```
if (structure.namedImports){
structure.namedImports.map((v)=>v.name) // type-checker error because of namedImports maybe WriteFunction
}
```

But we know , "getter structure" should not be WriteFunction .

**Describe the solution you'd like**

divide XXXStructure into XXXX-Getter-Structure and XXXX-setter-Structure

```
interface XXXX-Getter-Structure {
namedImport : string[] | undefined
}

interface XXXX-Setter-Strcture extends XXXX-Getter-Structure {
namedImport : string[] | undefined | WriteFunction
}
```

**Describe alternatives you've considered**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.