ES2015 module syntax is preferred over custom TypeScript modules and namespaces.eslint@typescript-eslint/no-namespace
TMInnovations opened this issue · 3 comments
TMInnovations commented
Bug Report
Can we omit namespace to satisfy eslint?
Current behavior
eslint throws error
Input Code
/**
* This file is auto-generated by nestjs-proto-gen-ts
*/
import { Observable } from 'rxjs';
import { Metadata } from '@grpc/grpc-js';
export namespace item {
export interface ItemService {
get(data: ItemById, metadata?: Metadata): Observable<Item>;
}
export interface ItemById {
id?: string;
}
export interface Item {
id?: string;
ownerId?: string;
value?: number;
}
}
Expected behavior
Generated code doesn't trigger eslint to throw red lines
Possible Solution
omit namespace
Environment
Nest version: 8.4.2
For Tooling issues:
- eslint: "^7.12.1"
Others:
AlexDaSoul commented
Hi! If you have some problems with syntax, you can copy the template from https://github.com/AlexDaSoul/nestjs-proto-gen-ts/blob/master/templates/nestjs-grpc.hbs, change this and run with parameter --template.
TMInnovations commented
I did exactly that. Would just be cool if the standard version wouldn't be incompatible with newer ES versions. If anyone has the same problem, my file now looks like:
/**
* This file is auto-generated by nestjs-proto-gen-ts
*/
import { Observable } from 'rxjs';
import { Metadata } from '@grpc/grpc-js';
{{#*inline "selector"}}
{{#each nested}}
{{#if fields}}
{{> type }}
{{else if methods}}
{{> service }}
{{else if values}}
{{> enum }}
{{else}}
{{> namespace }}
{{/if}}
{{/each}}
{{/inline}}
{{> selector }}
{{#*inline "namespace"}}
{{#if comment}}
{{comment}}
{{/if}}
{{> selector }}
{{/inline}}
{{#*inline "service"}}
{{#each methods}}
{{else}}
// tslint:disable-next-line:no-empty-interface
{{/each}}
{{#if comment}}
{{comment}}
{{/if}}
export interface {{@key}} {
{{#each methods}}
{{#if comment}}
{{comment}}
{{/if}}
{{#if this.requestStream}}
{{uncapitalize @key}}(data: Observable<{{this.requestType}}>, metadata?: Metadata): Observable<{{this.responseType}}>;
{{else}}
{{uncapitalize @key}}(data: {{this.requestType}}, metadata?: Metadata): Observable<{{this.responseType}}>;
{{/if}}
{{/each}}
}
{{> selector }}
{{/inline}}
{{#*inline "type"}}
{{#each fields}}
{{else}}
// tslint:disable-next-line:no-empty-interface
{{/each}}
{{#if comment}}
{{comment}}
{{/if}}
export interface {{@key}} {
{{#each fields}}
{{#if comment}}
{{comment}}
{{/if}}
{{@key}}?: {{type this}};
{{/each}}
}
{{#if nested}}
export namespace {{@key}} {
{{#if comment}}
{{comment}}
{{/if}}
{{> selector }}
}
{{/if}}
{{/inline}}
{{#*inline "enum"}}
{{#each values}}
{{else}}
// tslint:disable-next-line:no-empty-interface
{{/each}}
{{#if comment}}
{{comment}}
{{/if}}
{{var "comments" comments ~}}
export enum {{@key}} {
{{#each values}}
{{#if (enumComment @key)}}
{{enumComment @key}}
{{/if}}
{{@key}} = {{this}},
{{/each}}
}
{{/inline}}
AlexDaSoul commented
If there are a lot of appeals about it, we'll do it. But so far this is an isolated case, and therefore with this change we can break in