Skip to content

New node_modules/@types lookup needs prodding to include node.d.ts in build #9208

Closed
@yortus

Description

@yortus

After reading @DanielRosenwasser's new blog post about the support in typescript@next for looking up type declarations directly from node_modules/@types/<libname>, I did as the post suggested and gave it a shot. It works great and I really love this huge improvement to the typings story.

However the first thing I saw when I ripped out all remaining triple-slash references was a lot of TS2307: can't find module 'fs' (and similar) errors for node builtin modules. So I added an explicit triple-slash reference to "node_modules/@types/node/index.d.ts" and those errors went away.

The same thing happened with mocha, where the compiler couldn't find 'describe' or 'it' until I added a triple-slash reference to node_modules/@types/mocha/index.d.ts.

I guess this is the expected behaviour, since these are ambient typings. But in the case of the very widely-used node.d.ts typings, is there a shortcut so I can just npm install @types/node and then import * as fs from 'fs'?

Otherwise I hope this caveat will be clearly documented when 2.0 rolls out, since adding the explicit refs to "node_modules/@types/node/index.d.ts" is not the most obvious thing given the new 'automatic' lookup system.

Metadata

Metadata

Assignees

No one assigned

    Labels

    @typesRelates to working with .d.ts files (declaration/definition files) from DefinitelyTypedNeeds More InfoThe issue still hasn't been fully clarified

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions