Skip to content

Suggestion: typescript module resolution support #2254

Closed
@ValeryVS

Description

@ValeryVS

Update 1

app/
    shared/
        api-module/
        ui-module/
    heroes/
        heroes-list.component.ts
// tsconfig.json
{
  "compilerOptions": {
    "paths": {
      "#shared": [
        "app/shared"
      ]
    }
  }
}
// shared/index.ts
export * from './api-module/api.module';
export * from './api-module/api.service';
export * from './api-module/ui.module';
export * from './api-module/ui-notification.service';
export * from './api-module/ui-select.service';
// app/heroes/heroes-list.component.ts
import { Component } from '@angular/core';

import { ApiService } from '#api-module';
import {
    UINotyficationService,
    UISelectService
} from '#ui-module';

import { HeroesService } from './heroes.service.ts';

Original Post

TypeScript module resolution
microsoft/TypeScript#5039

Configs
Add baseUrl and, optionaly, paths to tsconfig.json

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "*": [ "modules/*" ]
    }
  }
}

Add modules to angular-cli.json apps

{
  "apps": [
    {
      "modules": [
        "src/modules"
      ]
  ]
}

Realisation
ValeryVS@c812fe8

Pros
Then we will be able to write
import { MyModule } from 'my';
and it will load module from src/modules/my/index.ts

We aslo can write src/app or src/app/shared to angular-cli.json and get rid of relative paths when we load services in app.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions