-
Notifications
You must be signed in to change notification settings - Fork 12.8k
How can I let JSDoc reference to type in another module #8237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Just found that reference module just work fine. It just cannot reference module name with Was JSDoc support reference module by ID? |
I am having hard time piecing together the repro. Can you provide a self-contained sample we can look at? |
I use tsd to pull aws-sdk.d.ts into typings folder And then as you can see. the code in aws-sdk.d.ts is The module name is What I want is something like
Current workaround I use is rename it in aws-sdk.d.ts as |
the module name shoudl not be used as an identifier. it works for some package, e.g. react, as they define a global variable import * as AWS from "aws-sdk";
/** @param {AWS.DynamoDB} dynamo */
function DoWork(dynamo) {
} |
@mhegazy That's work. But I still need to use it on node server under ES5 (AWS Lambda latest node version is nodejs 4) it cause error with reserved keyword So I try to find a way to have it work with only jsdoc comment Also I have seen there are syntax like this
So I made my own ts file and write
but it still didn't work |
So aws-sdk can be used without being imported? if so this is an error in the declaration file, and should be reported on definitely typed. |
For workarounds, neither or these would work. you want to use the new UMD module definition, (added in TS 2.0) #7125: /// file: my-aws-sdk.d.ts
export * from "aws-sdk"
export as namespace AWS; /// file: app.js
/// <reference path="my-aws-sdk.d.ts" />
/** @param {AWS.DynamoDB} dynamo */
function DoWork(dynamo) {
} |
@mhegazy No it's not. I mean I already try using import and it make intellisense work. But it cannot use in my target server so I can't use your solution That's that. so I need to wait for TS 2.0 Thank you very much for your help |
@mhegazy Also I would like to suggest that, in addition to yours |
Is there any support to pull in a type defined in a jsdoc from another file yet ? I want to use that type in another file file2.js how can I do that in typescript ? |
Tracked by #14377 |
I am trying to do something similar, I am using a karma.conf.js
VSCode just says |
^ I tried above with no luck. |
How would you reference something like firebase-admin type definition? https://unpkg.com/[email protected]/lib/index.d.ts It includes those definitions: // firebase-admin type definition
import {Bucket} from '@google-cloud/storage';
import * as _firestore from '@google-cloud/firestore';
declare namespace admin {
interface AppOptions {
credential?: admin.credential.Credential;
databaseAuthVariableOverride?: Object;
databaseURL?: string;
storageBucket?: string;
}
function app(name?: string): admin.app.App;
}
declare namespace admin.app {
interface App {
name: string;
options: admin.AppOptions;
}
}
declare namespace admin.firestore {
export import FieldPath = _firestore.FieldPath;
}
declare module 'firebase-admin' {
}
export = admin; If i try to bridge with: // lib/admin.d.ts
export * from 'firebase-admin';
export as namespace admin; If I reference // lib/index.js
// @ts-check
/// <reference path="./admin.d.ts" />
'use strict';
const admin = require('firebase-admin');
/**
* @type {admin.app.App|null}
*/
let defaultApp = null; |
for some people trying to use TS typings in plain JS, using JSDoc, sometimes I need to double export for it to work, like so: import * as winston from 'winston'
export = winston
export as namespace winston if you don't use /// <reference path="my-winston.d.ts" />
/**
* @type {winston.LoggerInstance | null}
*/
var logger = null |
Based on @mhegazy answer, but with plain const AWS = require('aws-sdk');
/**
* @param {AWS.DynamoDB} dynamo
*/
module.exports = function(dynamo){
return handler;
function handler(event, context, callback){
let msg = `We are running ${event.name}`;
console.log(msg)
callback(null, { msg });
}
} |
An ES6 import of types or a reference do not import anything at run time however. Even with that example where the caller would have to import that package anyway, a test might want to avoid any side effect of the import. |
I have some d.ts files in my project and any files without module could be reference any class inside it directly. But some files is declare module and cannot be referred to it
This module also contain - sign in its name (it is aws-sdk from aws-sdk.d.ts)
The text was updated successfully, but these errors were encountered: