-
-
Notifications
You must be signed in to change notification settings - Fork 80
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
Cannot use types when imported into TypeScript (5.1.6) #109
Comments
Not really sure what's wrong here; I can reproduce the problem, although even when I try exporting a namespace from iro.js I get similar errors I'm super busy at the moment so I'm afraid I don't really have time to dive into it fully, but hopefully someone more knowledgable than me when it comes to Typescript could help shed some light here |
Hi, I've checked this issue out. There is nothing wrong with the typescript declarations. When constructing the ColorPicker, we shouldnt call Instead, just use |
@Mocha-- Thanks for looking into it, however you missed the first part of my code where I cannot use iro.ColorPicker and iro.Color as types. I've found a workaround for it: import { IroColorPicker } from "@jaames/iro/dist/colorPicker";
import { IroColor } from "@irojs/iro-core";
import iro from "@jaames/iro";
class IroTest {
picker: IroColorPicker;
color: IroColor;
constructor() {
this.picker = iro.ColorPicker("#picker", {});
this.color = picker.color;
}
} But I don't think that is the intended usage. import iro from "@jaames/iro";
class Test {
test: iro.Color; // this line says: "semantic error TS2503: Cannot find namespace 'iro'"
} |
@drzony , sorry I missed the first issue that you cannot get the correct types. I guess two ways to fix it.
Option 1 is preferable personally. |
@Mocha-- Unfortunatelly that does not help, still getting "Cannot find namespace iro" |
Shouldn't be. Could you please check your node_modules/@jaames/iro/dist has index.d.ts? |
Yes, I've verified everything. I've created a new project and did a fresh "npm install" inside.
src/index.ts: import iro from "@jaames/iro";
export class Test {
picker: iro.ColorPicker;
color: iro.Color;
constructor() {
const div = document.createElement("div");
this.picker = iro.ColorPicker(div, {});
}
} package.json: {
"name": "iro_test",
"version": "1.0.0",
"description": "Test",
"main": "index.js",
"license": "MIT",
"dependencies": {
"@jaames/iro": "^5.1.6"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^11.0.2",
"@rollup/plugin-json": "^4.0.2",
"@rollup/plugin-node-resolve": "^7.1.1",
"@typescript-eslint/eslint-plugin": "^2.27.0",
"@typescript-eslint/parser": "^2.27.0",
"eslint": "^6.8.0",
"eslint-config-airbnb-base": "^14.1.0",
"eslint-config-prettier": "^6.10.1",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-prettier": "^3.1.2",
"prettier": "^1.19.1",
"rollup": "^1.32.1",
"rollup-plugin-serve": "^1.0.1",
"rollup-plugin-terser": "^5.3.0",
"rollup-plugin-typescript2": "^0.24.3",
"tldrlegal": "^1.0.11",
"typescript": "^3.8.3"
},
"scripts": {
"build": "rollup -c"
}
} tsconfig.json: {
"compilerOptions": {
"target": "es2017",
"module": "esnext",
"moduleResolution": "node",
"lib": ["es2017", "dom", "dom.iterable"],
"noEmit": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"strict": true,
"noImplicitAny": false,
"skipLibCheck": true,
"resolveJsonModule": true,
"experimentalDecorators": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true
}
} rollup.config.js: import typescript from "rollup-plugin-typescript2";
import nodeResolve from "@rollup/plugin-node-resolve";
const plugins = [nodeResolve(), typescript()];
export default [
{
input: "src/index.ts",
output: {
dir: "dist",
format: "es"
},
plugins: [...plugins]
}
]; Doing:
results in:
|
After reading up on exporting namespaces in TypeScript: I created a pull request that allows using exports as types. |
When importing iro.js in TypeScript:
For some reason exported object is not treated as a namespace, I tried to find out what is wrong, but came up empty.
When using the same code with 5.1.5 I get a warning about missing declaration, but everything works.
My tsconfig:
My rollup.js:
Are there any special options I need to use to compile it?
The text was updated successfully, but these errors were encountered: