user1365697
user1365697

Reputation: 5989

How to get type of ERRORS in TypeScript?

I used yaml https://www.npmjs.com/package/yaml I want to catch the error and to check the insatnce

    import * as yaml from 'yaml';
    try{
        const yamlParse: any = yaml.parse(data);   
    } catch(err){
    if ( err instanceof YAMLError) 
...
    }

The problem that the compile doesn't know YAMLError I tried also yaml.YAMLError

I define in package.json

"@types/yaml": "1.0.2",
    "yaml": "^1.5.1"

Upvotes: 0

Views: 147

Answers (1)

Nicolas Gehlert
Nicolas Gehlert

Reputation: 3253

you are probably missing the import import { YAMLError } from '@types/yaml'; on top

Upvotes: 1

Related Questions