ParameterDeclaration[] is not assignable to type 'OptionalKind<ParameterDeclarationStructure>[]'
- Dominant language
- TypeScript
- Stars
- 6.2k
- Forks
- 238
- Avg merge
- 2m
- Merged PRs (30d)
- 1
Description
**Describe the bug**
I try to pass parameters from `foo` method to `bar` method.
```
const cls = sourceFile.getClasses()[0];
const params = cls.getMethods()[0].getParameters();
sourceFile.addClass({
name: "bar",
methods: [{ name: "bar", parameters: params }] // <--- Not match. why??
});
```
But I got a typescript error:
```
Type 'ParameterDeclaration[]' is not assignable to type 'OptionalKind[]'.
Type 'ParameterDeclaration' is not assignable to type 'OptionalKind'.
Property 'name' is missing in type 'ParameterDeclaration' but required in type 'Pick'
```
https://codesandbox.io/s/ancient-river-ycucz5?file=/src/index.ts
Is there another way to do it?
Version: 16.0.0
**To Reproduce**
```ts
import { Project } from "ts-morph";
const project = new Project();
const sourceFile = project.createSourceFile(
"test.ts",
`
export class Foo {
foo(param) {
console.log({ param });
}
}
`
);
const cls = sourceFile.getClasses()[0];
const params = cls.getMethods()[0].getParameters();
sourceFile.addClass({
name: "bar",
methods: [{ name: "bar", parameters: params }] // <--- Not match. why??
});
```
Contributor guide
Assessment
This issue has not been assessed yet.