I'd like to import the Schema$ListMessagesResponse interface so I can validate the response that's returned.
I tried import { google, Schema$ListMessagesResponse } from 'googleapis'; but that doesn't work. I'm not familiar with importing this object from the package. It's documented here and here - How do I properly reference it?
https://googleapis.dev/nodejs/googleapis/latest/gmail/interfaces/Schema$Message.html
Node v12
TypeScript 4.3.5
You need to respect the given namespace gmail_v1 exporting the interface
try:
import {gmail_v1} from 'googleapis';
const messages: gmail_v1.Schema$ListMessagesResponse = //...
Related
I have dynamic module with params. I use params in his service.
How to import this module in service another module.
If I use this, I must add all parameters and another services, which I use there.
const serviceDynamicModule = new ServiceDynamicModule(param, service, ...);
I have found ModuleRef, but it doesn't contain this functionality.
You can import your module in another module by listing module you want to import to import section of another module's #module decorator.
Here is a explanation on Modules and dynamic module please check that out for more detail explanation. Nest_docs#dynamicModule
eg:-
lets say you want to import your dynamic module here.
import {Module} from '#nestjs/common';
#Module(
import:[yourDynamicModule.forRoot(neededParams)]
)
export calss MyModule{}
I want to organize my firebase cloud functions in specific files,
and currently, I have these 3:
index.ts
crypto.ts
webscrape.ts
Inside of these files, I have functions that use specific dependencies that are needed nowhere else.
For example, in crypto.ts I need the crypto-js package to encrypt some user data and store it into the database.
So I am importing it like so:
import * as CryptoJS from "crypto-js";
as advised in https://firebase.google.com/docs/functions/handle-dependencies#typescript
On the other hand, when I try to import puppeteer into webscrape.ts like this:
import * as puppeteer from"puppeteer-extra";
then calling puppeteer.launch(); gives me an error :
Property 'launch' does not exist on type 'typeof import("c:/Users/username/Desktop/project/firebasee/functions/node_modules/puppeteer-extra/dist/index")'
and it only works when I do const puppeteer = require("puppeteer-extra");
What's the difference here?
My goal is to keep the dependencies of each functions and file/module as small as possible because I assume that this will also keep the size of each function container small (Is that even true?)
I didn't want to import everything to index.ts even when I trigger a function, that doesn't use this dependency at all.
So what is the correct way of handling these dependencies?
Thanks!
The following import will get the default export from that package.
import puppeteer from "puppeteer-extra"
I looked for the default export in the Github repository and found that.
const defaultExport: PuppeteerExtra = (() => {
return new PuppeteerExtra(...requireVanillaPuppeteer())
})()
export default defaultExport
They have mentioned both ES6 import and require methods here.
// javascript import
const puppeteer = require('puppeteer-extra')
// typescript/es6 module import
import puppeteer from 'puppeteer-extra'
You can read more about import on MDN.
I was using this repo with Node.js:
https://www.npmjs.com/package/pg-essential
But now, with NestJS I'm having problems to make the import properly.
The original lines are:
var pg = require('pg');
require('pg-essential').patch(pg);
And using NestJS I can use: import * as pg from 'pg';
for the pg require, but how can import the second require?
You could do
import { patch } from 'pg-essential';
patch(pg);
Importing a named exporting and calling the function, instead of doing a chained require function.
I'm developing an Angular app.
For some reason I want to use querystring.escape().
I wrote import { escape } from 'querystring', but I got querystring.escape is not a function error.
How can I import a node module in typescript?
You are destructuring querystring trying to get the escape property, but then you want to call querystring.escape() which you haven't imported.
What you want to do is this:
import * as querystring from 'querystring';
or
import querystring from 'querystring'
Okay, as I can see you would like to use internal modules in your project. Well, there was a workaround in TypeScript 0.8.1.1, you could define non exported module (internal) and add imports above it. In 0.8.2 it seems that this doesn't work anymore. Only option I see here would be to completely omit import syntax and use standard require for node modules. I don't know if this is a good idea but please, share your opinions. I know that using import syntax will make module external (language specification), but that wasn't true in 0.8.1.1, bug maybe?
In TypeScript 0.8.1.1 this worked and doesn't work in 0.8.2 anymore:
import path = module('path');
import fs = module('fs');
module SomeNamespace.Controller {
export class Index {
...
}
}
I could reference file including above code using reference syntax on top of file in other internal modules and normally call:
var ctrl = new SomeNamespace.Controller.Index;
ctrl.index();
It seems that in 0.8.2 this is the only way what it works for internal modules:
var path = require('path');
var fs = require('fs');
module SomeNamespace.Controller {
export class Index {
...
}
}
Are there any other possibilities to mix internal modules with Node.js modules? Is there something wrong with above require usage (it compiles and runs okay ...)?
I think that TypeScript 0.8.2 takes us closer to the specification.
The syntax:
import x = module('SomeModule');
Is specifically an ExternalModuleReference in the TypeScript Language Specification.
An internal module would be imported using:
///<reference path="SomeModule.ts" />
import x = SomeModule;
But importing an internal module won't generate you a require statement in your JavaScript.
Taken from TypeScript Language Specification 0.8 - 9.2.2 Import Declarations
ImportDeclaration:
import Identifier = ModuleReference ;
ModuleReference:
ExternalModuleReference
ModuleName
ExternalModuleReference:
module ( StringLiteral )
Ok, this error is due to the version of the TypeScript.
In TypeScript 0.8.1.1 to import an external module the syntax has to be:
export import <moduleName> = module(“<path>”);
This is a bug identified in the latest version of TypeScript, you can return to the previous version or change the syntax to make it compatible with v0.8.1.1. Have in mind that this is a bug and in future versions, you should be able to use the original syntax.
This is the official thread for this bug:
http://typescript.codeplex.com/discussions/405800