Skip to content

Commit

Permalink
Fix missing this parameters
Browse files Browse the repository at this point in the history
Resolves #1875
  • Loading branch information
Gerrit0 committed Mar 6, 2022
1 parent 4350d47 commit 95fe32e
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,7 @@
### Bug Fixes

- Fixed validation for `--requiredToBeDocumented` option, #1872.
- Fixed missing `this` parameters in documentation for some functions, #1875.

## v0.22.12 (2022-02-20)

Expand Down
11 changes: 8 additions & 3 deletions src/lib/converter/factories/signature.ts
Expand Up @@ -58,10 +58,15 @@ export function createSignature(
signature.typeParameters
);

const parameterSymbols: ReadonlyArray<ts.Symbol & { type?: ts.Type }> =
signature.thisParameter
? [signature.thisParameter, ...signature.parameters]
: signature.parameters;

sigRef.parameters = convertParameters(
context,
sigRef,
signature.parameters as readonly (ts.Symbol & { type: ts.Type })[],
parameterSymbols,
declaration?.parameters
);

Expand Down Expand Up @@ -105,7 +110,7 @@ export function createSignature(
function convertParameters(
context: Context,
sigRef: SignatureReflection,
parameters: readonly (ts.Symbol & { type: ts.Type })[],
parameters: ReadonlyArray<ts.Symbol & { type?: ts.Type }>,
parameterNodes: readonly ts.ParameterDeclaration[] | undefined
) {
return parameters.map((param, i) => {
Expand All @@ -129,7 +134,7 @@ function convertParameters(
declaration
);

let type: ts.Type | ts.TypeNode;
let type: ts.Type | ts.TypeNode | undefined;
if (declaration) {
type = context.checker.getTypeOfSymbolAtLocation(
param,
Expand Down
4 changes: 4 additions & 0 deletions src/lib/types/ts-internal/index.d.ts
Expand Up @@ -22,6 +22,10 @@ declare module "typescript" {
): ts.TypePredicate | undefined;
}

export interface Signature {
thisParameter?: ts.Symbol;
}

// https://github.com/microsoft/TypeScript/blob/e213b2af3430bdc9cf5fbc76a8634d832e7aaaaa/src/compiler/types.ts#L5298-L5299
export interface UnionType {
/* @internal */
Expand Down
3 changes: 3 additions & 0 deletions src/test/converter2/issues/gh1875.ts
@@ -0,0 +1,3 @@
export declare function test(this: typeof globalThis, param: string): string;

export declare function test2(this, param: string): string;
2 changes: 2 additions & 0 deletions src/test/converter2/tsconfig.json
Expand Up @@ -6,6 +6,8 @@
"outDir": "dist",
"target": "ESNext",

"noImplicitAny": false,

// See #1524. We might force this to false eventually.
"skipLibCheck": true
},
Expand Down
14 changes: 14 additions & 0 deletions src/test/issueTests.ts
Expand Up @@ -292,6 +292,20 @@ export const issueTests: {
ok(project.children![1].kind !== ReflectionKind.Reference);
},

gh1875(project) {
const test = query(project, "test");
equal(
test.signatures?.[0].parameters?.map((p) => p.type?.toString()),
["typeof globalThis", "string"]
);

const test2 = query(project, "test2");
equal(
test2.signatures?.[0].parameters?.map((p) => p.type?.toString()),
["any", "string"]
);
},

gh1876(project) {
const foo = query(project, "foo");
const fooSig = foo.signatures?.[0].parameters?.[0];
Expand Down

0 comments on commit 95fe32e

Please sign in to comment.