Can't get Express #types working - express

I'm trying to get the Express #types working but without any success. I'm using Visual Studio Code and I'd really love to have the autocompletition working. So far I've seen that installing the #types it gives the autocompletition too.
Things that I've done:
Installed express with npm: npm i -g express
Installed express-generator with npm: npm i -g express-generator
Generated the project with express-generator
cd into the project
Ran npm i
Installed types with npm: npm i --save-dev #types/express
// Top of the file:
var express = require('express');
app.use(function (req, res: Express.Response, next) {
var err: any = new Error('Not Found');
//if I try to use res.end() it gets underlined in red
res.end('some text');
});
As you can see the Express.Response was suggested by vscode, so this kinda confuses me. How can you find the Express.Response type but not it's methods?
The 'funny' fact is that in plain js everything works. Am I missing something or doing something wrong?
Here's my tsconfig.json file if it can help:
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"baseUrl": "src",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"lib": [
"es2016",
"dom"
]
}
}
Any help will be really appreciated!

Solved by myself
For some reason now import * as express from 'express' now gives me the correct completition and type checking. However trying this before didn't worked. That's odd, however closing it as solved.

Related

No "eslint" targets found

I have a Gruntfile.js like this.
module.exports = function(grunt) {
require('time-grunt')(grunt);
require('load-grunt-config')(grunt, {
jitGrunt: {
staticMappings: {
scsslint: 'grunt-scss-lint'
}
}
});
grunt.loadNpmTasks('grunt-run');
grunt.registerTask('default', ['eslint', 'jest', 'scsslint', 'svgstore'])
};
And when I run the grunt it says.
grunt
No "eslint" targets found.
eslint is already installed and I even created the configuration file using
./node_modules/.bin/eslint --init
And this is the content of .eslintrc.js.
module.exports = {
"env": {
"browser": true,
"es2021": true,
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 13
},
"rules": {
}
};
Any opinions?
Depending on how you downloaded the codebase for the theme, it may be missing the "grunt" folder. If your project is missing this folder, try adding the one from Cornerstone: https://github.com/bigcommerce/cornerstone/tree/master/grunt
Per the BigCommerce documentation around eslint errors -- If bundling your theme triggers multiple lint errors related to the bundle.js file, your theme is missing the .eslintignore file.
You can retrieve this file from the Cornerstone repo. Once you add this in, re-run the bundle command.

Babel - VueJS | Module build failed: Error: Plugin/Preset files are not allowed to export objects, only functions. In

i tried to install preset-env for using environment variables. After that, my VueJS project got an error, i tried npm r #babel/preset-env, i tried npm i --save #babel-core but nothing changed. Any thoughts?
{
"presets": [
["env", { "modules": false }],
"stage-3",
],
"plugins": [["transform-runtime", { "polyfill": false, "regenerator": true }]]
}
Problem solved with using Babel version from vue.js webpack template repository.
npm r babel-core
add "babel-core": "^6.22.1" to package.json
npm i

The implementation option must be passed to the Sass task

Running grunt - I get this error message:
Running "sass:all" (sass) task
Fatal error: The implementation option must be passed to the Sass task
I've tried re-installing grunt, node, npm, dependencies - but I always come back to this error I can't get past.
Should I post my Gruntfile.js? Frankly, this was set up by a third-party and we don't use it often - I'm thinking maybe we should start from the ground up because it is from about 4 years ago originally... but wondering if anyone has seen this error before and knows of a fix/workaround.
With the update to grunt-sass 3, you have to choose whether you want to use node-sass or dart-sass to compile
For node-sass you need to install the module with:
$ npm install --save-dev node-sass
In you gruntfile, you than need to add node-sass as requirement and add the define constant as implementation option:
const sass = require('node-sass');
require('load-grunt-tasks')(grunt);
grunt.initConfig({
sass: {
options: {
implementation: sass,
sourceMap: true
},
dist: {
files: {
'main.css': 'main.scss'
}
}
}
});
See also official page for more details: https://www.npmjs.com/package/grunt-sass
use this
**const sass = require("node-sass");**
**grunt.initConfig({
sass: {
options: {
implementation: sass,
sourceMap: true,
},
dist: {
files: {
"css/styles.css": "css/styles.css",
},
},
},
});
This will help you solve the problem
UPDATE: Only works for grunt-sass 2.x
I had this problem when upgrading from grunt-sass 1.x to 2.x. This solved it for me:
Add implementation: 'sass' to your sass.options object in Gruntfile.js like so:
options: {
implementation: 'sass',
outputStyle: 'expanded',
sourceMap: true,
quiet: true // stop depreciation errors
},

polymer-cli - getting "Can’t find variable: babelHelpers" when I set compile to true

I use Polymer 2.0 and my build setting is:
"builds": [
{
"name": "bundled",
"bundle": true,
"js": { "compile": true},
"css": { "minify": true },
"html": { "minify": true }
}]
I get "Can’t find variable: babelHelpers" error after build.
The Polymer CLI version that I use is 1.1.0.
EDIT: I was using polymer-cli locally. After installing latest polymer-cli globally, now I get “Constructor requires ‘new’ operator” on safari and “Failed to construct ‘HTMLElement’: Please use the ‘new’ operator, this DOM object constructor cannot be called as a function.” on chrome.
EDIT2: used webcomponents-loader.js instead of webcomponents-lite.js and my problem solved.
I was getting same error. Problem was that index.html is technically my entrypoint in my polymer.json config, but my actual served up entrypoint is another file that comes from my server (_Layout.cshtml since I'm using .NET on my backend). What I needed to do was take the code in my compiled index.html file and move it over to my CSHTML file once I set "compile": true. Problem solved.

TypeScript Cannot find name 'Promise' intellisense error

I am getting a red squiggly intellisense error in TypeScript 2.1.4, Visual Studio 2015 Update 3 saying Cannot find name 'Promise', for example the following code shows the error on both uses of Promise:
/// <reference path="../typings/index.d.ts" />
import 'fetch';
import {HttpClient, json} from 'aurelia-fetch-client';
import {inject} from 'aurelia-framework';
import {BearerToken} from './common/bearer-token';
export class ApiToken
{
....
public getTokenSimplified(): Promise<BearerToken>
{
let tokenResult: BearerToken;
let p = new Promise<BearerToken>(function (resolve, reject)
{
// my code ommited
});
return p;
}
....
}
The TypeScript does compile without an error so I can get by with this, but I'd like to find a solution. Does anyone know how to solve this? Having researched StackOverflow and Github I have tried the following:
npm install es6-promise --save, and import {Promise} from 'es6-promise' added to the top of the source file
This does cause the red squiggly to disappear but leads to the build error "Type Promise is not assignable to type Promise. Two different types with this name exist but they are unrelated."
Installing and referencing npm's ts-promise incurs the same "Two different types with this name exist" error.
typings install dt~es6-shim --save --global
This causes duplicate definitions, e.g. Duplicate identifier 'PropertyKey' in lib.es2015.core.d.ts
typings install dt~es6-promise --save --global
This causes error Duplicate identifier 'Promise' in lib.es2015.iterable.d.ts
typings install bluebird --source npm --save
This fails with the compile time error "Type Promise is not assignable to type 'Bluebird'" because HttpClient returns Javascript Promises, not Bluebird promises.
npm install es6-shim --save and npm install #types/es6-shim --save-dev
This causes duplicate definitions, e.g. Duplicate identifier 'PropertyKey' in lib.es2015.core.d.ts
npm install es6-promise --save and npm install #types/es6-promise --save-dev
causes error Duplicate identifier 'Promise' in lib.es2015.iterable.d.ts
in tsconfig.json, modifying "lib": ["es2015", "dom"] to "lib": ["es2015", "es2015.promise", "dom"] did not fix the problem.
tscconfig.json as follows :
{
"compileOnSave": false,
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"sourceMap": true,
"target": "es5",
"module": "amd",
"declaration": false,
"noImplicitAny": false,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"lib": ["es2015", "dom"],
"baseUrl": "./",
"paths": {
"src/*": ["src/*"]
}
},
"filesGlob": [
"./src/**/*.ts",
"./test/**/*.ts",
"./typings/index.d.ts",
"./custom_typings/**/*.d.ts",
"./jspm_packages/**/*.d.ts"
],
"exclude": [
"node_modules",
"jspm_packages",
"dist",
"build",
"test"
],
"atom": {
"rewriteTsconfig": false
}
}
Perhaps I am not referencing the required library correctly so if someone can point out the error I'd appreciate it.
Try this config for libs
"lib": ["es2015", "dom", "es6"]
If other types are missing (Request, Response, BufferSource URLSearchParams,...) please send your typings.json file.