Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a type to an optional parameter marked by a question token puts the question token in the wrong spot #373

Closed
gregjacobs opened this issue Jul 24, 2018 · 2 comments
Labels

Comments

@gregjacobs
Copy link

Hey @dsherret. Looks like I found another interesting one. Trying to add a type to an optional parameter marked by a question token seems to put the '?' token in the wrong place in the output code. Check out this reproduction:

import Project, { MethodDeclaration, SyntaxKind } from 'ts-simple-ast';

const project = new Project();
const sourceFile = project.createSourceFile( 'my-file.ts', `
	class MyClass {
		someMethod( param1? ) {}
	}
` );


const method = sourceFile
	.getDescendantsOfKind( SyntaxKind.MethodDeclaration )[ 0 ] as MethodDeclaration;

const param1 = method.getParameters()[ 0 ];
param1.setType( 'any' );

console.log( 'Transformed:' );
console.log( sourceFile.getFullText() );

Basically the original source code:

class MyClass {
    someMethod( param1? ) {}
}

Gets changed into:

class MyClass {
    someMethod( param1: any? ) {}
}

Where the correct output should be:

class MyClass {
    someMethod( param1?: any ) {}
}

Best,
Greg

@dsherret
Copy link
Owner

As always, thanks for the excellent report @gregjacobs! Luckily for you I happened to be programming tonight so this is fixed now in 12.7.1.

@gregjacobs
Copy link
Author

@dsherret You're the man! Thanks so much for the fix, and so quickly! Much appreciated!

Best,
Greg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants