'Intl.Segmenter support in Deno

The MDN documentation says that Intl.Segmenter is supported in Deno version 1.8 and above. But when trying to use it, I get an error.

error: TS2339 [ERROR]: Property 'Segmenter' does not exist on type 'typeof Intl'.

My code is simply this:

const SEGMENTER = new Intl.Segmenter('en', { granularity: 'grapheme' });

And here's my Deno version info:

deno 1.20.4 (release, x86_64-unknown-linux-gnu)
v8 10.0.139.6
typescript 4.6.2

Am I missing something about why this wouldn't work?



Solution 1:[1]

It's there, but it doesn't seem to be in the type definitions, so that's why you are receiving the compiler error. You can either use a @ts- comment directive or the --no-check CLI run argument to avoid the compiler diagnostic and continue execution of your program:

example.ts:

const denoVersion = Deno.version.deno;
// @ts-expect-error
const segmenter = new Intl.Segmenter("en", { granularity: "grapheme" });
console.log({ denoVersion, segmenter });

> deno run example.ts
{ denoVersion: "1.20.4", segmenter: Intl.Segmenter {} }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jsejcksn