You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
assigning decode(someString) to something that expects a string causes es-lint typescript errors "Unsafe assignment of an any value." and "Unsafe call of an any typed value.
#69
Closed
aheggie opened this issue
Mar 12, 2022
· 1 comment
I haven't used many imported libraries with typescript so it is possible that I am making a fundamental typescript error around package imports
To be clear the app compiles and runs correctly, and the entities are in fact being stripped out. That said from my experience of other typed languages I know to take 'any' type seriously.
my use case is fairly simple essentially I am receiving from json a bunch of strings with html entities and working to process them to strings that do not have html entities:
import { decode } from "html-entities";
// this interface describes the json
interface Question {
category: string;
type: string;
difficulty: string;
//this is type of the string with html entitities in json
question: string;
correct_answer: string;
incorrect_answers: string[];
}
//this is the converted json the app expects
export interface Card {
category: string;
//this is the type of the string that should receive the results of decode
question: string;
answer: boolean;
hasBeenAnswered: boolean;
chosenAnswer?: boolean;
}
const questionToCard = ({
category,
question,
correct_answer,
}: Question): Card => ({
category: category,
// the following call to decode works but throws 2 typescript-eslint errors
question: decode(question),
answer: correct_answer === "True",
hasBeenAnswered: false,
})
I have read the documentation and searched elsewhere for references but I haven't seen a note about how to use this library with typescript without introducing any type into my codebase.
Have I made some error in importing or using the library? Or is this eslint error to be expected with standard use?
The text was updated successfully, but these errors were encountered:
I haven't used many imported libraries with typescript so it is possible that I am making a fundamental typescript error around package imports
To be clear the app compiles and runs correctly, and the entities are in fact being stripped out. That said from my experience of other typed languages I know to take 'any' type seriously.
my use case is fairly simple essentially I am receiving from json a bunch of strings with html entities and working to process them to strings that do not have html entities:
these are the two errors that are tthrown by typescript-eslint
https://github.com/typescript-eslint/typescript-eslint/blob/v4.16.1/packages/eslint-plugin/docs/rules/no-unsafe-assignment.md
https://github.com/typescript-eslint/typescript-eslint/blob/v4.16.1/packages/eslint-plugin/docs/rules/no-unsafe-call.md
I have read the documentation and searched elsewhere for references but I haven't seen a note about how to use this library with typescript without introducing any type into my codebase.
Have I made some error in importing or using the library? Or is this eslint error to be expected with standard use?
The text was updated successfully, but these errors were encountered: