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
typescript doc bug change "import fastify from 'fastify'" to "import { fastify } from 'fastify'" #4241
Comments
cc @fastify/typescript |
Typescript itself says, that you should then set moduleResolution to "node" or "nodeNext". Setting it to "node" or "nodeNext" fixes that issue. |
should add it in the doc of fastify on typescript by following the documentation as it is, there will be this problem |
Imho this is a common typescript issue. Also on the documentation of tsconfig https://www.typescriptlang.org/tsconfig#target
So we would be forced to keep our documentation up to date with the typescript versions and tbh I dont think we are responsible to set up the tsconfig properly. It is the responsibility of the programmer to set tsconfig correct and to know what he/she is doing by setting this or that option in tsconfig other than what we recommend in our docs. You are free to provide a PR to extend the documentation. But I think it is out of scope. I reopen it to get feedback by @mcollina , @jsumners or others. |
I said that it will be necessary to specify it due to the note on the target after yes I am talking about it because as it is there will be this error |
The strange thing is, that I dont get ts 2349 but ts 2792 if moduleResolution is set to "classic". If I use typescript 3.9.2 I get ts 2307. Using typescript version 4.0.2 up to next (4.9.0-dev.20220901) throws 2792. And 2792 clearly states to change the moduleResolution to "node". Other than that, I think an average developer will be able to fix that typescript issue without additional documentation. But still, why do you get 2349 and not 2792. |
ps: Setting it to "node" or "nodeNext" in tsconfig dont fix error node version : v16.16.0 package.json (currently migrate of express to fastify) {
"name": "xxxxxx",
"version": "0.0.0",
"description": "",
"type": "module",
"main": "build/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsc",
"start": "node build/index.js",
"dev": "concurrently \"tsc -w\" \"nodemon build/index.js\""
},
"author": "",
"license": "",
"dependencies": {
"@fastify/cors": "^8.1.0",
"@fastify/swagger": "^7.4.1",
"@prisma/client": "^3.15.2",
"bcrypt": "^5.0.1",
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"express": "^4.18.1",
"fastify": "^4.5.3",
"jsonwebtoken": "^8.5.1",
"minio": "^7.0.32",
"multer": "^1.4.5-lts.1"
},
"devDependencies": {
"@types/bcrypt": "^5.0.0",
"@types/cors": "^2.8.12",
"@types/express": "^4.17.13",
"@types/jsonwebtoken": "^8.5.9",
"@types/minio": "^7.0.13",
"@types/multer": "^1.4.7",
"@types/node": "^18.7.14",
"concurrently": "^7.3.0",
"json-schema-to-ts": "^2.5.5",
"nodemon": "^2.0.19",
"prisma": "^3.15.2",
"typescript": "^4.8.2"
}
} tsconfig {
"compilerOptions": {
/* Language and Environment */
"target": "ESNext" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
/* Modules */
"module": "ESNext" /* Specify what module code is generated. */,
"rootDir": "./src/" /* Specify the root folder within your source files. */,
"moduleResolution": "NodeNext" /* Specify how TypeScript looks up a file from a given module specifier. */,
/* JavaScript Support */
/* Emit */
"sourceMap": true /* Create source map files for emitted JavaScript files. */,
"outDir": "./build" /* Specify an output folder for all emitted files. */,
/* Interop Constraints */
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */
/* Type Checking */
"strict": true /* Enable all strict type-checking options. */,
/* Completeness */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
},
"compileOnSave": true,
"include": ["src/**/*.ts"]
} src/index.ts (go to minimal to generate erorr) import fastify from 'fastify'
const server = fastify() ts generate error on "fastify()" ts(2349) |
It is expected to have error when you use It require heavy refactor to support it. |
thanks to your respond @climba03003 with : ps : should still specify it in the note on the doc ^^ |
Can you provide a PR? |
add note in typescript doc to prevent ts(2349) warning fastify#4241
fastify#4241 seems to closed. Signed-off-by: Melroy van den Berg <melroy@melroy.org>
#4241 seems to closed. Signed-off-by: Melroy van den Berg <melroy@melroy.org>
Prerequisites
Fastify version
4.5.3
Plugin version
x.x.x
Node.js version
16.16.0
Operating system
Windows
Operating system version (i.e. 20.04, 11.3, 10)
win 11 ( insider )
Description
ts(2349) with current importl in doc when i call "fastify()"
Steps to Reproduce
npm init -y npm i fastify npm i -D typescript @types/node
Expected Behavior
no ts(2349) when following example
The text was updated successfully, but these errors were encountered: