Skip to content
This repository has been archived by the owner on Nov 24, 2020. It is now read-only.

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

Open
icaaro opened this issue Jul 4, 2018 · 2 comments

Comments

@icaaro
Copy link
Contributor

icaaro commented Jul 4, 2018

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 0cbc20c 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
Copy link
Contributor Author

icaaro commented Jul 4, 2018

@dygufa

@dygufa
Copy link
Contributor

dygufa commented Jul 4, 2018

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

0cbc20c#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?

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants