-
Notifications
You must be signed in to change notification settings - Fork 45
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
Fix typescript intellisense #39
Conversation
VS Code wasn't recognizing TypeScript types but that simple line fix it
@Martoxdlol just add |
@mathe42 at this point we should probably add this fallback type for default setups, it'd be easier to tell users to update their tsconfig if they want to resolve types for subpath imports down the line. |
I tried that in a new TS project and it didn't works index.ts import Surreal from 'surrealdb.js'
new Surreal() VS Code error
tsconfg.json {
"compilerOptions": {
"moduleResolution": "node16"
}
} package.json {
"name": "node_project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"surrealdb.js": "^0.4.0"
}
} |
use |
Thanks, that works. I took a sec to update the error but its working now. |
Before working on surrealdb.js I would agree but I think the Node16 option is much better and gives us so much more options! I think we should keep it but document it properly. |
The Node16 option is breaking a existing project imports. I'm not an expert in how exactly module resolution works with different configurations. I will research it and see what can i do. |
The There's the old |
Typescript here is wrong, we have the proper I reckon we should just switch to commonjs default + |
I failed making it work. It only worked for me changing the package.json of surrealdb.js. For now I will use my modified fork. |
It works using |
If I'm not mistaken it will only load the cjs output when using require as it is defined like that in the package.json:
To use the import syntax the developers are forced to convert their project to ESM. |
@Martoxdlol uh, should I have made another pr here instead of continuing from your pr? @btmnk by default, typescript uses es module syntax but still uses node's module resolution algorithm (implicit |
Nono, its ok. |
@Choooks22 I just wanted to clarify that it's normal to use .js file extensions in esm projects when the moduleResolution is set to Node16 or NodeNext even when using typescript. But there is still the issue that you can't import the lib in a commonjs project with the import statement.
Not sure if this was intended.. // EDIT: |
@Choooks22 I tried your repo cjs-with-require
cjs-with-require esm-with-import |
javascript/typescript are so complicated |
FYI I'm happy whatever you change for that - as long as it works. I (personaly) think that we should bundle the TS files into a single file. That would reduce most of the problems. (I personaly think the same about all build files this incluides esm an cjs). I think commonjs is getting completly replaced in the next 1-2 years so we might even remove the cjs build (personal opinion!). |
I agree with that |
cc @btmnk
That's because typescript automatically drops types when you use
This was the only repro that had proper settings and emitted files, and yes ES modules requires the Please note that while typescript does use ES module syntax, it doesn't mean that the emitted javascript files are ES modules. If the Also, while this error does get emitted when running
It works totally fine when you run the emitted javascript file, since we do have proper entrypoints. This should be a typescript compiler issue.
Update: I've found some blocking issues that would need updating... |
Do we have an update on this? |
I prefere #40 to be merged. |
VS Code wasn't recognizing TypeScript.
I added "types" key to the package.json.
It shouldn't change how anything works, but it does allow VS Code to recognize types correctly.