sdkgen icon indicating copy to clipboard operation
sdkgen copied to clipboard

Declaring a function with parameter called version produce a non-valid code in target typescript-node server code

Open icaaro opened this issue 7 years ago • 2 comments

When in sdkgen is created a function with param called "version" this produce a compile errors in node-server target.

Following below the error text produced by the behavior above.

ERROR in [at-loader] ./src/user/api.ts:2268:48 
        TS7022: 'version' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
    
    ERROR in [at-loader] ./src/user/api.ts:2268:109 
        TS2448: Block-scoped variable 'version' used before its declaration.
    
    ERROR in [at-loader] ./src/user/api.ts:2301:48 
        TS7022: 'version' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
    
    ERROR in [at-loader] ./src/user/api.ts:2301:118 
        TS2448: Block-scoped variable 'version' used before its declaration.
    
    ERROR in [at-loader] ./src/user/api.ts:2334:48 
        TS7022: 'version' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
    
    ERROR in [at-loader] ./src/user/api.ts:2334:111 
        TS2448: Block-scoped variable 'version' used before its declaration.
    
    ERROR in [at-loader] ./src/user/api.ts:2367:48 
        TS7022: 'version' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer
        
 ERROR in [at-loader] ./src/user/api.ts:2367:116 
        TS2448: Block-scoped variable 'version' used before its declaration.`

This bug is introduced by 0cbc20c05e4b29d2745a1e771f6d72574aa9dee5 commit. in the following line @io << ident ident ident ident "const {key, expirationSeconds, version} = await cacheConfig.#{op.pretty_name} (#{(["ctx"] + op.args.map(&.name)).join(", ")});\n"

I'm think the same occurs with functions with parameters called "key" and "expirationSeconds" .

icaaro avatar Jul 04 '18 00:07 icaaro

@dygufa

icaaro avatar Jul 04 '18 01:07 icaaro

This problem comes from the fact that the list of args share the same level as key, expirationSeconds and version:

https://github.com/cubos/sdkgen/commit/0cbc20c05e4b29d2745a1e771f6d72574aa9dee5#diff-2e1002b564cc16ba7695fa4740824bd5R98

@io << "export const cacheConfig: {\n"
@ast.operations.each do |op|
    args = ["ctx: Context"] + op.args.map { |arg| "#{arg.name}: #{arg.type.typescript_native_type}" }
    @io << "    " << op.pretty_name << "?: (#{args.join(", ")}) => Promise<{key: any, expirationSeconds: umber, version: number}>;\n"
end
@io << "} = {};\n\n"

I think the best solution would be inserting arg's keys/values inside an "args" key on the same level as key, expirationSeconds and version, preventing the override.

@davidcpires , what do you think?

dygufa avatar Jul 04 '18 02:07 dygufa