t4t5 / sweetalert

A beautiful replacement for JavaScript's "alert"
https://sweetalert.js.org
MIT License
22.38k stars 2.84k forks source link

Typescript usage: The supplied value [object Object] did not pass the test 'isJsonSourceFile' #885

Open SamanthaAdrichem opened 5 years ago

SamanthaAdrichem commented 5 years ago

When i try to import it in combination with Angular (7) and typescrip i get the following error:

Child process failed to process the request: Error: Debug Failure. Invalid cast. The supplied value [object Object] did not pass the test 'isJsonSourceFile'

if i use import swal from 'sweetalert'; swal is undefined. if i use any of the following i get the error as mentioned above

import * as swal from sweetalert

import * as _swal from 'sweetalert';
import { SweetAlert } from 'sweetalert/typings/core';
const swal: SweetAlert = _swal as any;

import swal = require('sweetalert')

Using the other sweetalert2 library does work, but I prefer to stay at this one. Tried it with the latest typescript 3.2.2 but also with specifically 3.1.6 as suggested

Any suggestions?

t4t5 commented 5 years ago

I'm not really sure if this is an issue with SweetAlert's typings or if it's due to a regression in TypeScript. It seems like people are having the same problem in other libraries too: https://github.com/Microsoft/TypeScript/issues/28762 (downgrading TypeScript to 3.1.6 seems to make the problem go away)

If anyone knows how to solve this, feel free to send a PR!

SamanthaAdrichem commented 5 years ago

For me downgrading to typescript 3.1.6 did not work though. I got the same error. Will try again.

Do you know what causes it? Then I could try and fix it and make a PR.

SamanthaAdrichem commented 5 years ago

edit, nvm, the downgrade to 3.1.6 failed big time..

t4t5 commented 5 years ago

Based on what I've found, I still think it's a regression in TypeScript's library. I believe it was fixed with this pull request, so either downgrading or using their nightly build might solve the problem.

Let me know how it goes!