0

I'm trying to create file with js:

const file = new File(['(⌐□_□)'], 'chucknorris.png', { type: 'image/png' });

and in chrome console it is file enter image description here

but in typescript playground it's empty object enter image description here

same thing happens while writing tests enter image description here

can someone explain the reason why this is happening?

tried passing new Blob(), ArrayBuffer as file bits, nothing changed.

  • 1
    Your File is fine, but you need to access all its properties yourself to log it: https://www.typescriptlang.org/play?#code/MYewdgzgLgBAZgSwDYFMYF4ZhQdxgMWRQAoBtAcmMARiQQtIB9GgSnIF0AaGc4ACwFdgA1mBAAnEQggA6AA5gA5uQ4BvGFACe0lAC5OCALYBDOSgD0shTAC+jANwAoUJBCpJSEHOKJUHLykkQEAC8UHyJJdU1QlyQDaABZEAATBEQURNsgA – Kaiido Nov 08 '22 at 09:49
  • @Kaiido by any chance do you know why trying to use `file.slice.arrayBuffer()` throws: TypeError: file.slice(...).arrayBuffer is not a function – Bartosz Ciach Nov 08 '22 at 10:26
  • `file.slice.arrayBuffer()`? You missed the `()` to call `slice()`, so you're trying to get the method on the function`.slice`. `file.slice().arrayBuffer()` seems to work in TS playground. – Kaiido Nov 08 '22 at 11:24

0 Answers0