Skip to content

Auto import in angular typescript is not working #28773

Description

  • VSCode Version:
    Version 1.29.1
    Typescript 3.1.4

  • OS Version:
    macOS 10.14.1

Steps to Reproduce:

  1. Create new angular app:
    ng new app

  2. Add new library:
    yarn add @datorama/akita

  3. Create session.model.ts:

export interface Session {
  id: ID;
  firstName: string;
  lastName: string;
  token: string;
}

Auto import is not working. I get this error:

[ts] Cannot find name 'ID'. [2304]
any

Starting VSCode with code --disable-extensions didn't help :(

Activity

  1. mjbvz commented on Nov 29, 2018

    @mjbvz

    Does this reproduce in the latest VS Code insiders build with all extensions disabled?

  2. micobarac commented on Nov 29, 2018

    @micobarac
    Author

    This happens with latest build both on macOS and Windows 10. A latest few builds, the autocomplete feels incosistent and partially working.

  3. micobarac commented on Nov 29, 2018

    @micobarac
    Author

    I tried restarting the app, but no good.

  4. micobarac commented on Nov 29, 2018

    @micobarac
    Author

    I haven't tried this insiders build. I am using the official final build.

  5. mjbvz commented on Nov 29, 2018

    @mjbvz

    Try on insiders

  6. micobarac commented on Nov 29, 2018

    @micobarac
    Author

    I've just tried insiders version on Windows 10. The problem is still there. Auto import is not picking up the definition inside installed @datorama/akita package:

    Cannot find name 'ID'.ts(2304)

    It gets even weirder with rxjs package. Definitions from rxjs are offered for auto import, but the ones inside rxjs/operators like mapTo cannot be found.

    The conclusion is that this auto import logic is obviously broken.

  7. mjbvz commented on Nov 30, 2018

    @mjbvz

    I confirmed this by using TS 3.3.0-dev20181130.

    The index.d.ts from akita has export * from './api/types'; which has an ID type. I see this error after trying to open the api/types file directly:

    Err 403   [11:12:21.819] Exception on executing command {"seq":65,"type":"request","command":"getApplicableRefactors","arguments":{"file":"/Users/matb/projects/san/node_modules/@datorama/akita/src/api/types.d.ts","startLine":1,"startOffset":1,"endLine":1,"endOffset":1}}:
    
        Could not find file: '/Users/matb/projects/san/node_modules/@datorama/akita/src/api/types.d.ts'.
    
        Error: Could not find file: '/Users/matb/projects/san/node_modules/@datorama/akita/src/api/types.d.ts'.
            at getValidSourceFile (/Users/matb/projects/san/node_modules/typescript/lib/tsserver.js:117240:23)
            at Object.getApplicableRefactors (/Users/matb/projects/san/node_modules/typescript/lib/tsserver.js:118017:24)
            at IOSession.Session.getApplicableRefactors (/Users/matb/projects/san/node_modules/typescript/lib/tsserver.js:125638:53)
            at Session.handlers.ts.createMapFromTemplate._a.(anonymous function) (/Users/matb/projects/san/node_modules/typescript/lib/tsserver.js:124512:61)
            at /Users/matb/projects/san/node_modules/typescript/lib/tsserver.js:125857:88
            at IOSession.Session.executeWithRequestId (/Users/matb/projects/san/node_modules/typescript/lib/tsserver.js:125848:28)
            at IOSession.Session.executeCommand (/Users/matb/projects/san/node_modules/typescript/lib/tsserver.js:125857:33)
            at IOSession.Session.onMessage (/Users/matb/projects/san/node_modules/typescript/lib/tsserver.js:125879:35)
            at Interface.<anonymous> (/Users/matb/projects/san/node_modules/typescript/lib/tsserver.js:127139:27)
            at emitOne (events.js:116:13)
            at Interface.emit (events.js:211:7)
            at Interface._onLine (readline.js:282:10)
            at Interface._normalWrite (readline.js:424:12)
            at Socket.ondata (readline.js:141:10)
            at emitOne (events.js:116:13)
            at Socket.emit (events.js:211:7)
            at addChunk (_stream_readable.js:263:12)
            at readableAddChunk (_stream_readable.js:250:11)
            at Socket.Readable.push (_stream_readable.js:208:10)
            at Pipe.onread (net.js:594:20)
    
  8. removed their assignment
    on Nov 30, 2018
  9. added
    BugA bug in TypeScript
    CrashFor flagging bugs which are compiler or service crashes or unclean exits, rather than bad output
    on Nov 30, 2018
  10. 12 remaining items

  11. removed
    CrashFor flagging bugs which are compiler or service crashes or unclean exits, rather than bad output
    on Jan 16, 2019
  12. micobarac commented on Mar 6, 2019

    @micobarac
    Author

    This is still not working, even with the latest VSCode version :(

  13. sheetalkamat commented on Jul 18, 2019

    @sheetalkamat
    Member

    Ryan Cavanaugh (@RyanCavanaugh) Daniel Rosenwasser (@DanielRosenwasser) This shouldn't be a bug but working as intended? WIthout the files being included in the project how can we know the symbol 'ID' is from @datorama/akita to offer it?

    Let me know if we need to take any other action here. Thanks

  14. added
    Working as IntendedThe behavior described is the intended behavior; this is not a bug
    and removed
    BugA bug in TypeScript
    on Jul 18, 2019
  15. smx-smx commented on Sep 16, 2019

    @smx-smx

    Is it possible to force tsserver to lookup all files up-front?

    If i'm using a lot of dependencies, or a large project with many dependencies, i would prefer to have tsserver scan all files up-front, so i don't have to find where every symbol is defined every time.

    As a user, i could choose between

    • performance (i know where symbols are, i am going to do a few imports only)
    • completeness (i can accept an initial performance tradeoff to get more pertinent results)

    I can see how doing this by default would make the process slower, so could this be an opt-in setting that forces tsserver to parse all files up-front eagerly? (user be warned: 'it will be slow', or something among those lines)

    Thank you

  16. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Domain: LS: TSServerIssues related to the TSServerWorking as IntendedThe behavior described is the intended behavior; this is not a bug

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions