I have some npm dependencies like socket.io or cheerio that provide type info for TS via the package.json types field.
This works just fine in a TS file such as server.ts:
import socketIO = require('socket.io')
socketIO.blah // correctly warns about property not existing
socketIO.Socket // correctly knows this exists
In javascript files however I get en error on the require line, ex in server.js:
// @ts-check
const socketIO = require('socket.io') // "Cannot find module 'socket.io' or its corresponding type declarations"
I did try and add a reference path comment/hint but that didn't work in server.js:
// @ts-check
/// <reference path='./node_modules/socket.io/dist/index.d.ts' />
const socketIO = require('socket.io') // "Cannot find module 'socket.io' or its corresponding type declarations"
However, type info comes through just fine for anything I've had to use DefinitelyTyped for. So for example if I have express as a dependency and @types/express as a devDependency then this works in server.js:
// @ts-check
const express = require('express')
express.blah // correctly warns about property not existing
express.static // correctly knows this exists
Seems like something is missing here when it comes to reading the types field off of package.json for dependencies. Is this just broken/missing functionality for javascript files or am I just missing some kind configuration or something?
I have some npm dependencies like socket.io or cheerio that provide type info for TS via the package.json types field.
This works just fine in a TS file such as server.ts:
In javascript files however I get en error on the require line, ex in server.js:
I did try and add a reference path comment/hint but that didn't work in server.js:
However, type info comes through just fine for anything I've had to use DefinitelyTyped for. So for example if I have
express
as a dependency and@types/express
as a devDependency then this works in server.js:Seems like something is missing here when it comes to reading the types field off of package.json for dependencies. Is this just broken/missing functionality for javascript files or am I just missing some kind configuration or something?