You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm basically trying to add the question token to function parameters that I know are optional, but I'm getting an error when trying to do so with parameters that don't yet have an explicit type. Take a look at this minimal repoduction:
importProject,{FunctionDeclaration,Identifier,Node,PropertyAccessExpression,SyntaxKind,TypeGuards}from'ts-simple-ast';constproject=newProject();constsourceFile=project.createSourceFile('my-file.ts',` function myFn( a, b ) {} // note: no types on these parameters`);constmyFn: FunctionDeclaration=sourceFile.getDescendants().find((node: Node): node is FunctionDeclaration=>{returnTypeGuards.isFunctionDeclaration(node)})!;constparams=myFn.getParameters();params[0].setHasQuestionToken(true);
On that last line, I get this error:
(21:56:00) ~/dev/js-to-ts-converter (master) $ ts-node test.ts
/Users/gjacobs/dev/js-to-ts-converter/node_modules/ts-simple-ast/dist/errors/BaseError.js:7
var _this = _super.call(this, message) || this;
^
Error: A child of the kind ColonToken was expected.
at InvalidOperationError.BaseError [as constructor] (/Users/gjacobs/dev/js-to-ts-converter/node_modules/ts-simple-ast/dist/errors/BaseError.js:7:28)
at new InvalidOperationError (/Users/gjacobs/dev/js-to-ts-converter/node_modules/ts-simple-ast/dist/errors/InvalidOperationError.js:8:28)
at Object.throwIfNullOrUndefined (/Users/gjacobs/dev/js-to-ts-converter/node_modules/ts-simple-ast/dist/errors/helpers.js:96:15)
at ParameterDeclaration.Node.getFirstChildByKindOrThrow (/Users/gjacobs/dev/js-to-ts-converter/node_modules/ts-simple-ast/dist/compiler/common/Node.js:1109:23)
at ParameterDeclaration.QuestionTokenableNode.class_1.setHasQuestionToken (/Users/gjacobs/dev/js-to-ts-converter/node_modules/ts-simple-ast/dist/compiler/base/QuestionTokenableNode.js:32:38)
at Object.<anonymous> (/Users/gjacobs/dev/js-to-ts-converter/test.ts:15:13)
at Module._compile (module.js:635:30)
at Module.m._compile (/usr/local/lib/node_modules/ts-node/src/index.ts:422:23)
at Module._extensions..js (module.js:646:10)
at Object.require.extensions.(anonymous function) [as .ts] (/usr/local/lib/node_modules/ts-node/src/index.ts:425:12)
It seems like I can add an explicit any type for the moment as a workaround, but figure this should work correctly too :)
The text was updated successfully, but these errors were encountered:
Hey @dsherret. So my latest utility is to convert a js codebase to ts (and it's open source this time so you can actually see it! https://github.com/gregjacobs/js-to-ts-converter)
I'm basically trying to add the question token to function parameters that I know are optional, but I'm getting an error when trying to do so with parameters that don't yet have an explicit type. Take a look at this minimal repoduction:
On that last line, I get this error:
It seems like I can add an explicit
any
type for the moment as a workaround, but figure this should work correctly too :)The text was updated successfully, but these errors were encountered: