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

Duplicated variables when doing --inline-imports #14

Open
lenowng opened this issue May 27, 2019 · 4 comments
Open

Duplicated variables when doing --inline-imports #14

lenowng opened this issue May 27, 2019 · 4 comments

Comments

@lenowng
Copy link

lenowng commented May 27, 2019

TS source:

Car-type.ts

export interface Manufacturer {
  name: string;
  country: string;
  heavyDutyTruckSpecialize: boolean;
  ..
}

export interface Car {
  manufacturer: Manufacturer;
  engine: string;
}

Bike-type.ts

export interface Manufacturer {
  name: string;
  country: string;
  ..
}

export interface Bike {
  manufacturer: Manufacturer;
  engine: string;
}

Vehicle-type.ts

import { CarType as Car } from './Car-type.ts'
import { BikeType as Bike } from './Bike-type.ts'
export interface Vehicle {
  type: CarType | BikeType;
}

Above scenario is sketched out to brings out the idea of the possible problem. Building interface type from Vehicle-type.ts with --inline-imports will lead to having duplicated variable named Manufacturer being generated in the same type file because import alias was not respected.

Suggestion: Use the import alias a prefix to generated variable name.

@darkalor
Copy link

darkalor commented Jul 26, 2022

The above example could likely be handled by just naming the manufacturer type differently between the files. Here's a simpler and more broken example that will result in the same error, even for a single Manufacturer type.
Haven't really found a workaround for this

// common.ts
export interface Manufacturer {
  name: string;
  country: string;
  ..
}

// engine.ts
export interface Engine {
  manufacturer: Manufacturer;
  engine: Engine;
}

// engine.ts
export interface Engine {
  name: String
  manufacturer: Manufacturer;
}

@ismakutl
Copy link

Any updates on this?

@darkalor
Copy link

darkalor commented Nov 25, 2022

FWIW my workaround ended up being something like this:

// validators.ts
const checkers = createCheckers(
  // EVERYTHING goes here
  fooSpecs,
  barSpecs
  commonSpecs
)

export default checkers
// foo.ts
import validator from 'utils/validator'
const FooValidator = validator.Foo

Essentially doing createCheckers once with everything, rather than making separate ones, which avoided multiple repeated definitions of the same thing. This doesn't fully solve the problem but it was sufficient for my use case

@dsagal
Copy link
Member

dsagal commented Nov 28, 2022

@fastfrwrd, since you added the --inline-imports option, do you have any suggestions here?

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

No branches or pull requests

4 participants