question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

mem intellisense broken for JS

See original GitHub issue

This issue matches PR #30. I think it’s better to have a discussion here.

I believe this issue applies to all your packages that recently added types via d.ts files. I assume that the purpose was to improve intellisense. Right now, it works fine for Typescript users who have --esModuleInterop turned on, but for normal JS use it’s broken:

const mem = require('./mem')

isn’t callable, even though the primary export of this package is a function.

Instead, people have to change their code to

const mem = require('./mem').default

which seems like it goes against the normal commonjs usage.

The d.ts file seems like it exists solely to provide better intellisense, and it consists solely of typescript syntax, so I think using the typescript syntax for commonjs exports make sense. That way people who use mem in editors with intellisense will not have to add .default to all their existing require('./mem') calls.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:34 (22 by maintainers)

github_iconTop GitHub Comments

2reactions
BendingBendercommented, Mar 23, 2019

There are 2 options:

// 1st
import foo = require('foo');

const fooVal: foo.Foo = ...;
foo.namedExportFn();

// 2nd
import foo = require('foo');
import {namedExportFn, Foo} from 'foo';

If your default export is a class the whole definition becomes much more awkward:

declare namespace Foo {
	// Only interfaces may be declared here. If you have a value,
	// you'll need to declare it as a static member on the class
	// or via an intersection type.
}

declare class Foo {}

export = Foo;
2reactions
weswighamcommented, Mar 21, 2019

Why wouldn’t mem be directly callable provided @sindresorhus moves his modules to ESM, which he plans to do?

As I said, if both consumer and producer are esm, it’d work fine, but if mem is still cjs (eg, because a consumer’s dependency is locked to this version), the default member of the default import is what’s going to be needed to work (according to the type definitions).

Lemme be blunt with y’all: DO NOT WRITE DECLARATION FILES TODAY FOR TOMORROW’S NODE ESM IMPLEMENTATION.

  1. How it works is still in flux. What you think works today might not tomorrow, or there may be a better way tomorrow.
  2. Because of how it’s likely to work at present, we (as in TS) will likely need to augment declaration files with some kind of “node-esm-only” marker (since it behaves very differently than the transpiled esm es syntax in a declaration file represents today, and we’ll need to flag it’s usage from commonjs). We’ll be deciding how that works once everything interop wise is decided and it’s about to unflag, which is optimistically October. So any declaration file written today will, ofc, not have that marker.
  3. Declarations that don’t accurately reflect (current) reality are dangerous. Ultimately that means incorrect intellisense results, and a drop in type coverage for a program.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Intellisense for Javascript in VSCode not working
Intellisense for Javascript in VSCode not working · Works fine for me. · Can you put a screenshot on imgur of a JS...
Read more >
IntelliSense not working for Typescript project
IntelliSense does not seem to be working at all on .ts files within my team's project. Upon opening a TS file, usually after...
Read more >
JavaScript and TypeScript in Visual Studio | Microsoft Learn
Learn how Visual Studio provides rich support for JavaScript development, both using JavaScript directly, and also using the TypeScript ...
Read more >
How To Resolve IntelliSense Issue In Visual Studio - C# Corner
Check if CS.Proj is corrupted or not. If this is the case, then try to add back or fix it. Solution 5. Run...
Read more >
Fixing Intellisense and Go To Definition in Visual Studio 2019
Potential Solution #3: Use the NuGet UI ... The next thing I could think to do was use the NuGet UI within Visual...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found