How do I tell deno check to ignore this?

> deno check cli/color-test.ts config.ts


Check file:///Users/dan/xall/aStuff/cli/color-test.ts
error: TS2322 [ERROR]: Type 'string' is not assignable to type 'ENVIRONMENTS'.
const ENV: ENVIRONMENTS = the_env || "unspecified";
~~~
at file:///Users/dan/xall/aStuff/cli/color-test.ts:6:7
> deno check cli/color-test.ts config.ts


Check file:///Users/dan/xall/aStuff/cli/color-test.ts
error: TS2322 [ERROR]: Type 'string' is not assignable to type 'ENVIRONMENTS'.
const ENV: ENVIRONMENTS = the_env || "unspecified";
~~~
at file:///Users/dan/xall/aStuff/cli/color-test.ts:6:7
9 Replies
Antonio Sampaio
type your variables
Doctor 🤖
Doctor 🤖2y ago
const ENV = (the_env || 'unspecified') as unknown as ENVIRONMENTS
dan.the.discloser
thank you. ?? Is there a way to just tell the deno checker to ignore it ??
Doctor 🤖
Doctor 🤖2y ago
That forces typescript to shut up but it doesn’t mean the code will work.
dan.the.discloser
agreed.
Doctor 🤖
Doctor 🤖2y ago
I like to do type Force = any then do 5 as Force when I know something will work but don’t want it to complain.
dan.the.discloser
thank you. I understand. so there no way in deno checker to just turn it off for the next line (?) may I asked you another typing question? Is there anyway I can get the ENVIRONMENTS type other than manually like this?
export const COLORS = {
exp: { log: "yellow", site: "lightYellow" },
unspecified: { log: "magenta", site: "lightPurple" },
test: { log: "red", site: "pink" },
shared: { log: "green", site: "lightGreen" },
dev: { log: "blue", site: "lightBlue" },
odd: { log: "cyan", site: "lightBlue" },
};



export type ENVIRONMENTS =
"exp" | "unspecified" | "test" | "shared" | "dev" | "odd"
export const COLORS = {
exp: { log: "yellow", site: "lightYellow" },
unspecified: { log: "magenta", site: "lightPurple" },
test: { log: "red", site: "pink" },
shared: { log: "green", site: "lightGreen" },
dev: { log: "blue", site: "lightBlue" },
odd: { log: "cyan", site: "lightBlue" },
};



export type ENVIRONMENTS =
"exp" | "unspecified" | "test" | "shared" | "dev" | "odd"
Doctor 🤖
Doctor 🤖2y ago
You could make environments an enum. Types of are just meant to be sugar on top to understand things. It will all be stripped when transpiled to js. Enums will be values you can actually use to check if certain info is correct.
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View