-?-?-?-?-?-?-?-?-?-?-
-?-?-?-?-?-?-?-?-?-?-
TTCTheo's Typesafe Cult
Created by -?-?-?-?-?-?-?-?-?-?- on 12/19/2023 in #questions
πŸ“¦ERR_UNSUPPORTED_DIR_IMPORT - ES modules
Hello! Im not sure there is place for help in SWC configure , but i will try because i cant find help (Im gonna remove that if it will be problem). Last time i have problem with error ERR_UNSUPPORTED_DIR_IMPORT which is throwing after launching compiled file with SWC. I wanted to do cli node app which will use dir imports like that:
// utils is directory with files (functions) and everyone of them are exported at index.ts which is 'default' file of directory
βœ…
import {func1,func2,func3} from "utils"
import func4 from "func4File"
❌
import {func1,func2,func3} from "utils/index.js"
import func4 from "func4File.js"

❌
import {func1,func2,func3} from "utils/index.ts"
import func4 from "func4File.ts"
// utils is directory with files (functions) and everyone of them are exported at index.ts which is 'default' file of directory
βœ…
import {func1,func2,func3} from "utils"
import func4 from "func4File"
❌
import {func1,func2,func3} from "utils/index.js"
import func4 from "func4File.js"

❌
import {func1,func2,func3} from "utils/index.ts"
import func4 from "func4File.ts"
I used it many times at nextjs projects and i basically thought it was typescript compiler fixing but i was wrong (I was learning Ts induring next) My first thought it was problem it's with Typescript compiler and i asked on they DC but someone told me problem it's because it's standard ES modules requirement and that was working before because Bundler like SWC was fixing that issues (next js have many plugins) I was reading SWC Docs, i notice in config exportDefaultFrom and im thinking it can be this but it cannot be combined with "syntax": "typescript" So, my questions are: - It's possible to do it like i want? I - How can i do that? There is option/plugin for this or something? - Should i try to use other builder? REPO https://github.com/INeedJobToStartWork/helpme (Problem it's with /bin, not nextjs app)
3 replies
TTCTheo's Typesafe Cult
Created by -?-?-?-?-?-?-?-?-?-?- on 4/24/2023 in #questions
How to use arguments property from function in TS
Is it possible to use arguments from Function in TS or i have to use rest operator? Because when im trying to do this, im getting error:Expected 0 arguments, but got 4.ts(2554) JS Example
function sum() {
let result = 0;
for (let i = 0; i < arguments.length; i++) {
result += arguments[i];
}
return result;
}

console.log(sum(1, 2, 3, 4));
// Expected Output: 10
function sum() {
let result = 0;
for (let i = 0; i < arguments.length; i++) {
result += arguments[i];
}
return result;
}

console.log(sum(1, 2, 3, 4));
// Expected Output: 10
3 replies