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.

Typescript ambient definitions doesnt work in node unless

See original GitHub issue

unless you require it as an “ecmascript module”

const { default: chalk } = require('chalk') // this will work and typescript is happy

The following provides incorrect types:

const chalk = require('chalk') // this work but typescript will shows errors with incorrect types

Would it be possible to fix the index.d.ts so it provides correct types for commonjs (node) environment?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
alesmenzelcommented, May 31, 2020

You were right, sorry for bothering. It was a misconfiguration in my project… Again, I am sorry and thanks for all answers. Still it is weird it was working with the const {default: chalk} = require('chalk') import.

0reactions
Qix-commented, May 31, 2020

I am using plain node v12 but have Typescript intellisense running on those js files.

This doesn’t make much sense to be honest. JS is too dynamic to have great intellisense. I didn’t even know IDEs would cross the typescript/javascript boundary when doing code hinting.

Sounds like an issue specifically with your IDE as our typings haven’t caused any issues before.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Declare node module for TypeScript that is not available ...
I'm quite new to TypeScript and am trying to script a little cli app. I want to use npm~command-line-args but its definition is...
Read more >
Ambient Modules in TypeScript: What they are and how to ...
An ambient declaration file is a file that describes the module's type but doesn't contain its implementation.
Read more >
Documentation - Modules - TypeScript
How modules work in TypeScript. ... We call declarations that don't define an implementation “ambient”. Typically, these are defined in .d.ts files. If...
Read more >
What are Ambients in TypeScript ? - GeeksforGeeks
We have to always write ambient declarations if our TypeScript code needs ... JavaScript libraries such as jQuery, AngularJS, Node.js, etc.
Read more >
typescript-cheatsheet - GitHub Pages
TypeScript, like JavaScript, allows you to work with arrays of values. ... We call declarations that don't define an implementation “ambient”.
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