<?xml version="1.0" encoding="ISO-8859-1"?>

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
	<channel>
		<title>Forum du club des développeurs et IT Pro - TypeScript</title>
		<link>https://www.developpez.net/forums/</link>
		<description>Forum sur le développement TypeScript, langage de développement libre et open source développé par Microsoft, en tant que sur ensemble de JavaScript. Avant de poster : Cours TypeScript et FAQ TypeScript.</description>
		<language>fr</language>
		<lastBuildDate>Sun, 31 May 2026 05:34:03 GMT</lastBuildDate>
		<generator>vBulletin</generator>
		<ttl>15</ttl>
		<image>
			<url>https://forum.developpez.be/images/misc/rss.png</url>
			<title>Forum du club des développeurs et IT Pro - TypeScript</title>
			<link>https://www.developpez.net/forums/</link>
		</image>
		<item>
			<title>Microsoft annonce la version bêta de TypeScript 7.0, basée sur le langage Go</title>
			<link>https://www.developpez.net/forums/showthread.php?t=2183350&amp;goto=newpost</link>
			<pubDate>Wed, 22 Apr 2026 11:04:49 GMT</pubDate>
			<description>*Microsoft annonce la version...</description>
			<content:encoded><![CDATA[<div><b><font size="4">Microsoft annonce la version bêta de TypeScript 7.0, basée sur le langage Go, avec des performances « 10 fois plus rapides » que la version 6.0, des capacités de traitement parallèle et bien plus encore</font></b><br />
<br />
<b>Microsoft a annoncé la sortie de TypeScript 7.0 Beta, marquant ainsi le lancement de la version bêta publique de la refonte, basée sur Go, du compilateur et de la suite d'outils du langage. Cette version est présentée comme un changement architectural majeur pour le langage, Microsoft affirmant que la nouvelle implémentation est « <a href="https://typescript.developpez.com/actu/369976/Un-TypeScript-10x-plus-rapide-Anders-Hejlsberg-architecte-principal-de-Microsoft-pour-TypeScript-presente-un-nouveau-portage-de-TypeScript-qui-offrira-aux-developpeurs-un-outil-de-haute-performance/" target="_blank">environ dix fois plus rapide que TypeScript 6.0</a> ». Bien qu'il s'agisse d'une version bêta, l'entreprise affirme que le compilateur est prêt pour la production. TypeScript 7.0 Beta est entièrement compatible avec TypeScript 6.0 et apporte plusieurs nouveautés visant à améliorer ses performances, sa stabilité et sa compatibilité.</b><br />
<br />
TypeScript (TS) est un langage de programmation de haut niveau qui ajoute à JavaScript un typage statique avec des annotations de type facultatives. Il est conçu pour le développement d'applications volumineuses et est compilé en JavaScript. TypeScript est développé par Microsoft en tant que logiciel libre et open source, distribué sous licence Apache 2.0. En mars 2025, Microsoft a annoncé que son équipe travaillait sur une version du compilateur TypeScript portée sur Go, qui devrait être publiée sous le nom de TypeScript 7.0. En décembre de la même année, il a été annoncé sur le blog de l'entreprise que TypeScript 6.0 serait la dernière version écrite en TypeScript lui-même, et que TypeScript 7.0 serait la première version basée sur Go.<br />
<br />
L'annonce de TypeScript 7.0 Beta est importante non seulement parce qu'elle fait avancer le calendrier de publication de TypeScript 7, mais aussi parce qu'elle officialise l'abandon de l'implémentation de longue date basée sur JavaScript. Dans le billet officiel publié le 21 avril, Microsoft a indiqué que cette version bêta reposait sur « une base entièrement nouvelle », créée en portant le code source existant de TypeScript vers Go, tout en conservant le même comportement de vérification des types et la même sémantique auxquels les développeurs sont déjà habitués.<br />
<br />
« Nous sommes ravis d’annoncer la sortie de TypeScript 7.0 Beta. Si vous n’avez pas suivi le développement de TypeScript 7.0, sachez que cette version est importante car elle repose sur une base entièrement nouvelle. Au cours de l'année écoulée, nous avons porté le code source existant de TypeScript vers Go. Grâce à la combinaison de la vitesse du code natif et du parallélisme en mémoire partagée, TypeScript 7.0 est souvent environ 10 fois plus rapide que TypeScript 6.0. », a déclaré Daniel Rosenwasser, chef de produit principal chez Microsoft.<br />
<br />
<div style="text-align: center;">
<div class="video-container"><iframe class="restrain" title="YouTube video player" width="560" height="315" allowfullscreen src="//www.youtube.com/embed/GwoN21Sk8tM?wmode=transparent&amp;fs=1" frameborder="0"></iframe></div>
</div><br />
Microsoft a également profité du lancement de cette version bêta pour affirmer de manière directe que le compilateur était prêt, alors qu'il s'agit d'une version bêta. Dans l'annonce, Daniel Rosenwasser a écrit : « Ne vous laissez pas tromper par la mention « bêta » : vous pouvez probablement commencer à l'utiliser dès maintenant dans votre travail quotidien. Le nouveau code source Go a été méthodiquement porté à partir de notre implémentation existante plutôt que réécrit à partir de zéro, et sa logique de vérification des types est structurellement identique à celle de TypeScript 6.0. Cette parité architecturale garantit que le compilateur continue d'appliquer exactement la même sémantique à laquelle vous êtes déjà habitué.  »<br />
<br />
Il a ajouté que TypeScript 7.0 a « été évalué à l'aide de l'énorme suite de tests que nous avons constituée au cours de la dernière décennie, et est déjà utilisé dans de nombreuses bases de code comptant plusieurs millions de lignes, tant au sein de Microsoft qu'à l'extérieur. Il est extrêmement stable, hautement compatible et prêt à être mis à l'épreuve dès aujourd'hui dans vos workflows quotidiens et vos pipelines d'intégration continue »<br />
<br />
Selon Daniel Rosenwasser, l'équipe de TypeScript collabore depuis plus d'un an avec de nombreuses équipes internes de Microsoft, ainsi qu’avec des équipes d’entreprises telles que Bloomberg, Canva, Figma, Google, Lattice, Linear, Miro, Notion, Slack, Vanta, Vercel, VoidZero et bien d’autres, afin de tester des versions préliminaires de TypeScript 7.0 sur leurs bases de code. Rosenwasser affirme que « les retours ont été extrêmement positifs : de nombreuses équipes ont signalé des gains de vitesse similaires, réduisant considérablement leurs temps de compilation, et ont bénéficié d'une expérience d'édition beaucoup plus légère et fluide. »<br />
<br />
<b><font size="3">Utilisation de TypeScript 7.0 Beta</font></b><br />
<br />
Pour obtenir TypeScript 7.0 Beta, les utilisateurs peuvent l'installer via npm :<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">npm install <span style="color: black;">-</span>D <span style="color: black;">@</span>typescript<span style="color: black;">/</span>native<span style="color: black;">-</span>preview<span style="color: black;">@</span>beta</code><hr />
</div><br />
Remarque : le nom du paquet sera éventuellement remplacé par <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">typescript</span> dans une prochaine version.<br />
<br />
À partir de là, les utilisateurs peuvent exécuter <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">tsgo</span> à la place de l'exécutable <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">tsc</span>.<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><table cellspacing="0" cellpadding="0"><tr><td valign="top" width="26"><div style="border: 1px dashed gray; padding-left: 5px; padding-right: 5px; margin-right: 5px; text-align: right; font-family: monospace">1<br />2<br /></div></td><td valign="top"><pre style="margin: 0"><span style="color: black;">&gt;</span> npx tsgo <span style="color: black;">--</span>version
Version 7.0.0<span style="color: black;">-</span>beta</pre></td></tr></table></code><hr />
</div><br />
L'exécutable <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">tsgo</span> se comporte de la même manière que <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">tsc</span> de TypeScript 6.0 sur tout le code TypeScript, mais il est bien plus rapide, selon Microsoft.<br />
<br />
Pour tester cette expérience d'édition, les utilisateurs peuvent installer l'extension TypeScript Native Preview pour VS Code. Microsoft affirme que la prise en charge par l'éditeur est extrêmement fiable et qu'elle est largement utilisée par de nombreuses équipes depuis plusieurs mois déjà. C'est un moyen simple et fluide d'essayer immédiatement TypeScript 7.0 sur la base de code. Elle repose sur les mêmes fondements que l'expérience en ligne de commande, ce qui permet aux utilisateurs de bénéficier des mêmes améliorations de performances dans leur éditeur que sur la ligne de commande. Microsoft précise par ailleurs qu'elle s'appuie également sur le protocole Language Server Protocol, ce qui facilite son exécution dans la plupart des éditeurs modernes, voire dans des outils tels que Copilot CLI.<br />
<br />
<b><font size="3">Utilisation en parallèle avec TypeScript 6.0</font></b><br />
<br />
Afin d'aider les utilisateurs à passer de TypeScript 6.0 à TypeScript 7.0, la version bêta est disponible via le paquet <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">@</span>typescript<span style="color: black;">/</span>native<span style="color: black;">-</span>preview</span> en utilisant le point d'entrée <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">tsgo</span>. Cela permet de valider et de comparer facilement les résultats de <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">tsc</span> et de <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">tsgo</span>. Cependant, la version stable de TypeScript 7.0 sera publiée sous le paquet typescript et utilisera le point d'entrée <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">tsc</span>.<br />
<br />
De plus, Microsoft indique que même si la version 7.0 Beta est presque prête pour la production, l'équipe TypeScript ne disposera pas d'une API programmatique stable avant au moins plusieurs mois, avec TypeScript 7.1. Dans ce contexte, elle s'est fixé comme priorité de garantir que TypeScript puisse fonctionner en parallèle avec TypeScript 6.0 dans un avenir proche, sans aucun conflit quant à « quel tsc est le bon ? ».<br />
<br />
Dans le cadre du processus de transition de la version 6.0 vers la 7.0, Microsoft a publié un nouveau paquet de compatibilité, <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">@</span>typescript<span style="color: black;">/</span>typescript6</span>. Ce paquet expose un nouveau point d'entrée, <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">tsc6</span>, afin que les utilisateurs puissent, si nécessaire, exécuter la prochaine version de TypeScript 7.0 (qui fournira un binaire <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">tsc</span>) en parallèle sans conflit de noms. Il réexportera également l'API TypeScript 6.0, ce qui permettra aux développeurs d'utiliser <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">tsc</span> pour TypeScript 7, tandis que les autres outils pourront continuer à s'appuyer sur la version 6.0.<br />
<br />
Étant donné que certains outils, tels que typescript-eslint, s'attendent à ce que les importations soient effectuées directement depuis TypeScript via des dépendances entre pairs, Microsoft recommande d'utiliser des alias npm à cette fin. Les utilisateurs devraient pouvoir exécuter la commande suivante :<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">npm install <span style="color: black;">-</span>D typescript<span style="color: black;">@</span>npm<span style="color: black;">:@</span>typescript<span style="color: black;">/</span>typescript6</code><hr />
</div><br />
ou modifiez leurs fichiers <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: #0000ff;">package</span>.<span style="color: #0080ff;">json</span></span> comme suit :<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><table cellspacing="0" cellpadding="0"><tr><td valign="top" width="26"><div style="border: 1px dashed gray; padding-left: 5px; padding-right: 5px; margin-right: 5px; text-align: right; font-family: monospace">1<br />2<br />3<br />4<br />5<br /></div></td><td valign="top"><pre style="margin: 0"><span style="color: black;">&#123;</span>
  <span style="color: #FF0000;">&quot;devDependencies&quot;</span><span style="color: black;">:</span> <span style="color: black;">&#123;</span>
    <span style="color: #FF0000;">&quot;typescript&quot;</span><span style="color: black;">:</span> <span style="color: #FF0000;">&quot;npm:@typescript/typescript6@^6.0.0&quot;</span><span style="color: black;">,</span>
  <span style="color: black;">&#125;</span>
<span style="color: black;">&#125;</span></pre></td></tr></table></code><hr />
</div><br />
Microsoft indique qu'elle fournira à l'avenir des instructions plus précises concernant l'utilisation d'un tsc alimenté par TS7 parallèlement à un tsc6 alimenté par TS6.<br />
<br />
<b><font size="3">Parallélisation et contrôles</font></b><br />
<br />
TypeScript 7.0 exécute désormais de nombreuses étapes en parallèle, notamment l'analyse syntaxique, la vérification des types et la génération de code. Certaines de ces étapes, comme l'analyse syntaxique et la génération de code, peuvent généralement être effectuées indépendamment d'un fichier à l'autre. Ainsi, la parallélisation s'adapte automatiquement aux bases de code plus volumineuses avec une surcharge relativement faible. Cependant, Microsoft précise que toutes les étapes d'une compilation TypeScript ne se prêtent pas facilement à la parallélisation.<br />
<br />
<b><font size="2">Parallélisation des vérificateurs de types</font></b><br />
<br />
Selon l'équipe TypeScript, des étapes, comme la vérification des types, présentent des dépendances plus complexes entre les fichiers. La plupart des fichiers finissent par s'appuyer sur les mêmes informations de type provenant de leurs dépendances et de la portée globale ; par conséquent, exécuter les vérificateurs de types de manière totalement indépendante serait un gaspillage, tant en termes de calcul que de mémoire. D'autre part, la vérification des types s'appuie parfois sur l'ordre relatif des informations dans un programme ; par conséquent, une vérification des types effectuée à partir de zéro doit toujours vérifier les mêmes fichiers dans un ordre identique pour garantir les mêmes résultats.<br />
<br />
Pour permettre la parallélisation tout en évitant ces écueils, TypeScript 7.0 crée un nombre fixe de processus de vérification de types, chacun disposant de sa propre vision du monde. Ces processus de vérification de types peuvent finir par dupliquer certaines tâches communes, mais, à partir des mêmes fichiers d'entrée, ils les répartiront toujours de manière identique et produiront les mêmes résultats.<br />
<br />
Le nombre par défaut de processus de vérification de types est de 4, mais il peut être configuré à l'aide du nouveau flag <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">--checkers</span>. Les utilisateurs constateront peut-être qu'augmenter ce nombre permet d'accélérer encore davantage les compilations sur des bases de code volumineuses, où les machines disposent généralement de plus de cœurs de processeur, mais cela s'accompagnera généralement d'une augmentation de la consommation de mémoire. De même, sur les machines dotées d'un nombre réduit de cœurs de processeur (par exemple, les serveurs CI) , il peut être préférable de réduire ce nombre afin d'éviter une surcharge inutile.<br />
<br />
Microsoft indique que, dans de rares cas, le fait de modifier le nombre de vérificateurs peut faire apparaître des résultats dépendant de l'ordre d'exécution. Le fait de fixer un nombre de vérificateurs pour l'ensemble d'une équipe peut donc contribuer à garantir que tout le monde obtienne les mêmes résultats, mais cette décision relève de la discrétion de chaque équipe.<br />
<br />
<b><font size="2">Parallélisation des compilateurs de références de projet</font></b><br />
<br />
TypeScript 7.0 permet de paralléliser les compilations au sein d'un même projet, mais il est désormais également possible de compiler plusieurs projets simultanément. Ce comportement peut être configuré à l'aide du nouveau drapeau <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span>builders</span>, qui détermine le nombre de compilateurs de références de projet pouvant s'exécuter en parallèle. Cette fonctionnalité peut s'avérer particulièrement utile pour les monorepos contenant de nombreux projets.<br />
<br />
Tout comme l'option <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">--checkers</span>, Microsoft précise qu'augmenter le nombre de processeurs de compilation peut accélérer la compilation, mais cela peut se traduire par une augmentation de la consommation de mémoire. Cela a également un effet multiplicateur avec l'option <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">--checkers</span> ; il est donc important pour l'utilisateur de trouver le bon équilibre pour sa machine et sa base de code. Par exemple, une compilation avec <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span>checkers <span style="color: #cc66cc;">4</span> <span style="color: black;">--</span>builders <span style="color: #cc66cc;">4</span></span> permet à jusqu'à 16 vérificateurs de types de s'exécuter simultanément, ce qui peut s'avérer excessif.<br />
<br />
Cependant, contrairement à l'option <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">--checkers</span>, le fait de modifier le nombre de compilateurs ne devrait pas entraîner de résultats différents ; toutefois, la compilation des références de projet est fondamentalement limitée par le graphe des dépendances des projets (à l'exception de la vérification des types sur les bases de code qui utilisent l'option <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span>isolatedDeclarations</span> et génèrent des fichiers de déclarations syntaxiques séparés).<br />
<br />
<b><font size="2">Mode mono-thread</font></b><br />
<br />
Microsoft indique que dans certains cas, il peut être utile d'imposer un fonctionnement mono-thread à l'ensemble du compilateur. Cela peut s'avérer utile pour le débogage, pour comparer les performances avec TypeScript 6 et 7, lors de l'orchestration de builds parallèles en externe, ou pour l'exécution dans des environnements aux ressources très limitées. Pour activer le mode monothread, les utilisateurs peuvent recourir au nouveau drapeau <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span>singleThreaded</span>. Cela limitera non seulement le nombre de workers chargés de la vérification des types à 1, mais garantira également que l'analyse et l'émission s'effectuent dans un seul thread.<br />
<br />
<b><font size="3">Mises à jour depuis la version 5.x et nouveaux comportements à partir de la version 6.0</font></b><br />
<br />
TypeScript 7.0 est conçu pour être compatible avec le système de vérification des types et le comportement en ligne de commande de TypeScript 6.0. Tout code TypeScript qui se compile sans erreur avec TypeScript 6.0 (avec le drapeau <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">stableTypeOrdering</span> activé et sans le drapeau <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">ignoreDeprecations</span> défini) devrait se compiler de la même manière dans TypeScript 7.0.<br />
<br />
TypeScript 7.0 reprend les nouvelles valeurs par défaut de la version 6.0 et génère des erreurs critiques en cas d'utilisation de drapeaux ou de constructions obsolètes dans TypeScript 6.0. Microsoft encourage les développeurs à adopter TypeScript 6.0 afin de faciliter la transition vers TypeScript 7.0. <br />
<br />
En résumé, les principaux changements apportés aux paramètres par défaut sont les suivants :<br />
<br />
<ul><li style=""> <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">strict</span> est défini sur <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">true</span> par défaut.</li><li style=""> <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: #0000ff;font-weight:bold">module</span></span> est défini par défaut sur <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">esnext</span>.</li><li style=""> <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">target</span> est défini par défaut sur la version stable d'ECMAScript immédiatement antérieure à <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">esnext</span>.</li><li style=""> <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">noUncheckedSideEffectImports</span> est défini sur <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">true</span> par défaut.</li><li style=""> <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">libReplacement</span> est défini sur <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: #339933;">false</span></span> par défaut</li><li style=""> <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">stableTypeOrdering</span> est défini sur <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">true</span> par défaut et ne peut pas être désactivé.</li><li style=""> <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">rootDir</span> est désormais défini par défaut sur <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">.<span style="color: black;">/</span></span>, et les répertoires de sources internes doivent être spécifiés explicitement.</li><li style=""> <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">types</span> est désormais défini par défaut sur <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">&#91;</span><span style="color: black;">&#93;</span></span>, et l'ancien comportement peut être rétabli en le définissant sur <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">&#91;</span><span style="color: #FF0000;">&quot;*&quot;</span><span style="color: black;">&#93;</span></span>.</li></ul><br />
L'équipe TypeScript estime que les modifications apportées à <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">rootDir</span> et <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">types</span> sont peut-être les plus « surprenantes », mais qu'elles peuvent être facilement gérées. Pour les projets dans lesquels le fichier <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">tsconfig.<span style="color: #0080ff;">json</span></span> se trouve en dehors d'un répertoire tel que <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">src</span>, il suffira d'inclure <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">rootDir</span> pour conserver la même structure de répertoires.<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><table cellspacing="0" cellpadding="0"><tr><td valign="top" width="26"><div style="border: 1px dashed gray; padding-left: 5px; padding-right: 5px; margin-right: 5px; text-align: right; font-family: monospace">1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td valign="top"><pre style="margin: 0">  <span style="color: black;">&#123;</span>
      <span style="color: #FF0000;">&quot;compilerOptions&quot;</span><span style="color: black;">:</span> <span style="color: black;">&#123;</span>
          <span style="color: #808080;">// ...</span>
<span style="color: black;">+</span>         <span style="color: #FF0000;">&quot;rootDir&quot;</span><span style="color: black;">:</span> <span style="color: #FF0000;">&quot;./src&quot;</span>
      <span style="color: black;">&#125;</span><span style="color: black;">,</span>
      <span style="color: #FF0000;">&quot;include&quot;</span><span style="color: black;">:</span> <span style="color: black;">&#91;</span><span style="color: #FF0000;">&quot;./src&quot;</span><span style="color: black;">&#93;</span>
  <span style="color: black;">&#125;</span></pre></td></tr></table></code><hr />
</div><br />
<br />
En raison du changement de <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">types</span>, les projets qui dépendent de déclarations globales spécifiques devront les mentionner explicitement. Par exemple :<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><table cellspacing="0" cellpadding="0"><tr><td valign="top" width="26"><div style="border: 1px dashed gray; padding-left: 5px; padding-right: 5px; margin-right: 5px; text-align: right; font-family: monospace">1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td valign="top"><pre style="margin: 0">  <span style="color: black;">&#123;</span>
      <span style="color: #FF0000;">&quot;compilerOptions&quot;</span><span style="color: black;">:</span> <span style="color: black;">&#123;</span>
          <span style="color: #808080;">// Explicitly list the @types packages you need (e.g. bun, mocha, jasmine, etc.)</span>
<span style="color: black;">+</span>         <span style="color: #FF0000;">&quot;types&quot;</span><span style="color: black;">:</span> <span style="color: black;">&#91;</span><span style="color: #FF0000;">&quot;node&quot;</span><span style="color: black;">,</span> <span style="color: #FF0000;">&quot;jest&quot;</span><span style="color: black;">&#93;</span>
      <span style="color: black;">&#125;</span>
  <span style="color: black;">&#125;</span></pre></td></tr></table></code><hr />
</div><br />
<br />
Les dépréciations qui sont désormais traitées comme des erreurs critiques sans comportement no-op sont les suivants :<br />
<br />
<ul><li style=""> <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">target <span style="color: black;">:</span> es5</span> n'est plus pris en charge.</li><li style=""> <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">downlevelIteration</span> n'est plus pris en charge.</li><li style=""> <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">moduleResolution <span style="color: black;">:</span> node<span style="color: black;">/</span>node10</span> ne sont plus pris en charge ; il est recommandé d'utiliser <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">nodenext</span> et <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">bundler</span> à la place.</li><li style=""> <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: #0000ff;font-weight:bold">module</span> <span style="color: black;">:</span> amd<span style="color: black;">,</span> umd<span style="color: black;">,</span> systemjs<span style="color: black;">,</span> none</span> ne sont plus pris en charge ; il est recommandé d'utiliser <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">esnext</span> ou <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">preserve</span> en conjonction avec des bundlers ou la résolution de modules basée sur le navigateur.</li><li style=""> <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">baseUrl</span> n'est plus pris en charge, et <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">paths</span> peut être mis à jour pour être relatifs à la racine du projet au lieu de baseUrl.</li><li style=""> <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">moduleResolution<span style="color: black;">:</span> classic</span> n'est plus pris en charge ; il est recommandé d'utiliser <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">bundler</span> ou <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">nodenext</span> à la place.</li><li style=""> <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">esModuleInterop</span> et <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">allowSyntheticDefaultImports</span> ne peuvent plus être définis sur <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: #339933;">false</span></span>.</li><li style=""> <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">alwaysStrict</span> est considéré comme <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">true</span> et ne peut plus être défini sur <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: #339933;">false</span></span>.</li><li style=""> Le mot-clé <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: #0000ff;font-weight:bold">module</span></span> ne peut pas être utilisé dans les déclarations d'espace de noms.</li><li style=""> Le mot-clé <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">asserts</span> ne peut pas être utilisé sur les importations ; il faut utiliser le mot-clé <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: #0000ff;">with</span></span> à la place (pour s'aligner sur les développements de la syntaxe de l'attribut import d'ECMAScript).</li><li style=""> Les directives <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: #808080;">/// &lt;reference no-default-lib /&gt;</span></span> ne sont plus respectées sous <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">skipDefaultLibCheck</span>.</li><li style=""> Les builds en ligne de commande ne peuvent pas accepter de chemins de fichiers lorsque le répertoire courant contient un fichier <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">tsconfig.<span style="color: #0080ff;">json</span></span>, sauf passage explicite du drapeau <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span>ignoreConfig</span>.</li></ul><br />
<b><font size="3">Différences au niveau de JavaScript</font></b><br />
<br />
Lors du portage du code existant, Microsoft en a également profité pour revoir le fonctionnement de sa prise en charge de JavaScript.<br />
<br />
À l'origine, TypeScript prenait en charge les fichiers JavaScript en utilisant les commentaires JSDoc et en reconnaissant certains modèles de code à des fins d'analyse et d'inférence de types. La plupart du temps, cela reposait sur des modèles de codage courants, mais parfois, cela reposait sur tout ce que les développeurs pouvaient écrire et que Closure et l'outil de génération de documentation JSDoc étaient capables de comprendre. Bien que cette approche ait été utile pour les développeurs disposant de bases de code JSDoc rédigées de manière informelle, Microsoft indique qu'elle nécessitait un certain nombre de compromis et de cas particuliers pour fonctionner correctement, et s'écartait à plusieurs égards de l'analyse effectuée par TypeScript dans les fichiers <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">.<span style="color: #0080ff;">ts</span></span>.<br />
<br />
Dans TypeScript 7.0, Microsoft a remanié la prise en charge de JavaScript afin de la rendre plus cohérente avec la manière dont sont analysés les fichiers TypeScript. Voici quelques-unes des différences :<br />
<br />
<ul><li style=""> Les valeurs ne peuvent pas être utilisées là où des types sont attendus ; à la place, écrivez <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: #0000ff;font-weight:bold">typeof</span> someValue</span>.</li><li style=""> <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">@</span><span style="color: #0000ff;font-weight:bold">enum</span></span> n'est plus reconnu ; créez un <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">@</span>typedef</span> sur <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">&#40;</span><span style="color: #0000ff;font-weight:bold">typeof</span> YourEnumDeclaration<span style="color: black;">&#41;</span><span style="color: black;">&#91;</span>keyof <span style="color: #0000ff;font-weight:bold">typeof</span> YourEnumDeclaration<span style="color: black;">&#93;</span></span>.</li><li style=""> Un <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">?</span></span> seul n'est plus utilisable comme type ; utilisez plutôt <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: #0080ff;">any</span></span>.</li><li style=""> <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">@</span><span style="color: #0000ff;font-weight:bold">class</span></span> ne transforme pas une fonction en constructeur ; utilisez plutôt une déclaration <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: #0000ff;font-weight:bold">class</span></span>.</li><li style=""> Le suffixe <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">!</span></span> n'est pas pris en charge – utilisez simplement <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">T</span>.</li><li style=""> Les noms de types doivent être définis dans une balise <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">@</span>typedef</span> (c'est-à-dire <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: #808080;">/** @typedef {T} TypeAliasName */</span></span>), et non à côté d'un identifiant (c'est-à-dire <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: #808080;">/** @typedef {T} */</span> TypeAliasName<span style="color: black;">;</span></span>).</li><li style=""> La syntaxe des fonctions de type fermeture (par exemple <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: #0000ff;font-weight:bold">function</span><span style="color: black;">&#40;</span><span style="color: #0080ff;">string</span><span style="color: black;">&#41;</span><span style="color: black;">:</span> <span style="color: #0080ff;">void</span></span>) n'est plus prise en charge – utilisez plutôt les raccourcis TypeScript (par exemple <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">&#40;</span>s<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">&#41;</span> <span style="color: black;">=&gt;</span> <span style="color: #0080ff;">void</span></span>).</li></ul><br />
De plus, certaines pratiques JavaScript, comme l'aliasing de `this` et la réaffectation de l'intégralité du <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">prototype</span> d'une fonction, ne font plus l'objet d'un traitement particulier.<br />
<br />
<b><font size="3">Expérience dans l'éditeur</font></b><br />
<br />
Les améliorations apportées aux performances de TypeScript 7.0 ne se limitent pas à l'utilisation en ligne de commande : elles s'étendent également à l'expérience dans l'éditeur. L'extension « TypeScript Native Preview » pour VS Code permet d'essayer TypeScript 7.0 en toute transparence dans l'éditeur.<br />
<br />
« Depuis son lancement, nous avons ajouté des fonctionnalités qui faisaient défaut, telles que l'importation automatique, les survols extensibles, les astuces intégrées, les loupes de code, l'accès direct à la définition dans le code source, l'édition liée JSX et la complétion de balises, entre autres. De plus, nous avons entièrement repensé une grande partie de notre infrastructure de tests et de diagnostics afin de garantir un niveau de qualité élevé », a déclaré Daniel Rosenwasser. « Cette extension reprend la plupart des paramètres de configuration de l'extension TypeScript intégrée à Visual Studio Code, ainsi que la plupart de ses fonctionnalités. Même si certaines fonctionnalités sont encore en cours de développement (comme la mise en évidence sémantique, des commandes plus spécifiques pour la gestion des importations, etc.), l'extension est déjà puissante, stable et rapide. »<br />
<br />
<b><font size="3">Travaux à venir</font></b><br />
<br />
Au cours des prochaines semaines, Microsoft prévoit de déployer une implémentation plus efficace de l'option <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span>watch</span> et d'atteindre la parité en matière de génération de fichiers de déclaration à partir de fichiers JavaScript. L'entreprise travaillera également sur des lacunes mineures au niveau des fonctionnalités de l'éditeur, telles que la recherche de références de fichiers depuis l'explorateur de fichiers, ainsi que sur la mise en avant de commandes plus précises comme « Trier les importations » et « Supprimer les importations inutilisées », en lieu et place de la commande plus générale « Organiser les importations ».<br />
<br />
Microsoft indique également qu'elle développera une API programmatique stable pour TypeScript 7.1 ou une version ultérieure, qu'elle améliorera son infrastructure de tests en conditions réelles et qu'elle prendra en compte les commentaires reçus.<br />
<br />
« La version bêta de TypeScript 7.0 étant désormais disponible, l'équipe se concentre sur la correction des bogues, les travaux de compatibilité, la mise au point de l'éditeur et l'amélioration des performances en vue d'une version stable. Nous prévoyons actuellement de publier TypeScript 7.0 dans les deux prochains mois, avec une version candidate disponible quelques semaines auparavant. La version candidate marquera, selon nos prévisions, la finalisation du comportement de TypeScript 7 ; les modifications apportées par la suite porteront principalement sur la correction des régressions critiques », a conclu Daniel Rosenwasser.<br />
<br />
<b>Source :</b> <a rel="nofollow" href="https://devblogs.microsoft.com/typescript/announcing-typescript-7-0-beta/" target="_blank">Microsoft</a><br />
<br />
<b>Et vous ?</b><br />
<br />
:fleche: Quel est votre avis sur le sujet ?<br />
:fleche: Que pensez-vous des nouveautés proposées par cette version de TypeScript ? Les trouvez-vous utiles et intéressantes ?<br />
<br />
<b>Voir aussi :</b><br />
<br />
:fleche: <a href="https://typescript.developpez.com/actu/381479/Microsoft-annonce-TypeScript-6-0-apportant-des-ameliorations-aux-fonctions-sensibles-au-contexte-la-prise-en-charge-des-importations-de-sous-chemins-et-des-changements-pour-preparer-TypeScript-7-0/" target="_blank">Microsoft annonce TypeScript 6.0 apportant des améliorations aux fonctions sensibles au contexte, la prise en charge des importations de sous-chemins et des changements pour préparer TypeScript 7.0</a><br />
<br />
:fleche: <a href="https://typescript.developpez.com/actu/374164/Microsoft-annonce-la-version-candidate-RC-de-TypeScript-5-9-apportant-des-mise-a-jour-a-tsc-moins-init-ainsi-que-la-prise-en-charge-de-import-defer-et-de-moins-module-node20/" target="_blank">Microsoft annonce la version candidate (RC) de TypeScript 5.9 apportant des mise à jour à tsc --init ainsi que la prise en charge de import defer et de --module node20</a><br />
<br />
:fleche: <a href="https://typescript.developpez.com/actu/370629/TypeScript-se-tourne-vers-Gopher-Microsoft-mise-sur-Go-pour-multiplier-la-vitesse-par-10-par-Kush-Creates/" target="_blank">TypeScript se tourne vers Gopher : Microsoft mise sur Go pour multiplier la vitesse par 10, par Kush Creates</a></div>

]]></content:encoded>
			<category domain="https://www.developpez.net/forums/f2001/javascript/typescript/">TypeScript</category>
			<dc:creator>Anthony</dc:creator>
			<guid isPermaLink="true">https://www.developpez.net/forums/d2183350/javascript/typescript/microsoft-annonce-version-beta-typescript-7-0-basee-langage-go/</guid>
		</item>
		<item>
			<title>Microsoft annonce la version stable de TypeScript 6.0</title>
			<link>https://www.developpez.net/forums/showthread.php?t=2182070&amp;goto=newpost</link>
			<pubDate>Thu, 12 Feb 2026 13:42:51 GMT</pubDate>
			<description>*Microsoft annonce la version...</description>
			<content:encoded><![CDATA[<div><b><font size="4">Microsoft annonce la version Beta de TypeScript 6.0 apportant des améliorations aux fonctions sensibles au contexte ainsi que la prise en charge des importations de sous-chemins</font></b><br />
<br />
<b>Microsoft annonce la version Beta de TypeScript 6.0. Voici quelques-uns des points forts de cette version : moins de sensibilité au contexte pour les fonctions sans this, importations de sous-chemins commençant par #/, combinaison de --moduleResolution bundler avec --module commonjs, le drapeau --stableTypeOrdering, l'option es2025 pour target et lib, entre autres. TypeScript 6.0 est une version unique en son genre, car son équipe a l'intention d'en faire la dernière version basée sur le code source JavaScript actuel. Comme annoncé en 2025, ils travaillent sur un nouveau code source pour le compilateur TypeScript et le service linguistique écrit en Go qui tire parti de la vitesse du code natif et du multithreading à mémoire partagée.</b><br />
<br />
TypeScript est un langage qui s'appuie sur JavaScript en ajoutant une syntaxe pour les types. L'écriture de types dans le code permet d'expliquer l'intention et de faire vérifier le code par d'autres outils pour détecter les erreurs comme les fautes de frappe, les problèmes avec <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">null</span> et <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: #339933;">undefined</span></span>, et plus encore. Les types alimentent également les outils d'édition de TypeScript, comme l'auto-complétion, la navigation dans le code et les refactorisations que vous pouvez voir dans des éditeurs tels que Visual Studio et VS Code. En fait, TypeScript et son écosystème alimentent l'expérience JavaScript dans ces deux éditeurs également.<br />
<br />
TypeScript 6.0 est une version unique en son genre, car son équipe a l'intention d'en faire la dernière version basée sur le code source JavaScript actuel. Comme annoncé en 2025, ils travaillent sur un nouveau code source pour le compilateur TypeScript et le service linguistique écrit en Go qui tire parti de la vitesse du code natif et du multithreading à mémoire partagée. Cette nouvelle base de code constituera le fondement de TypeScript 7.0 et des versions ultérieures. TypeScript 6.0 sera le précurseur immédiat de cette version et, à bien des égards, il servira de pont entre TypeScript 5.9 et 7.0. À ce titre, la plupart des changements apportés à TypeScript 6.0 visent à faciliter l'alignement et la préparation à l'adoption de TypeScript 7.0.<br />
<br />
<div style="text-align: center;"><img src="https://www.developpez.net/forums/attachments/p674204d1770988851/javascript/typescript/microsoft-annonce-version-stable-typescript-6-0/1.jpg/" border="0" alt="Nom : 1.jpg
Affichages : 11606
Taille : 10,6 Ko"  style="float: CONFIG" /></div><br />
Voici quelques-uns des points forts de cette version, avec des détails sur ce qui va changer dans la version 7.0 :<br />
<br />
<b><font size="3">Moins de sensibilité au contexte pour les fonctions sans this</font></b><br />
<br />
Lorsque les paramètres n'ont pas de types explicites, TypeScript peut généralement les déduire en fonction d'un type attendu, ou même à partir d'autres arguments dans le même appel de fonction.<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><table cellspacing="0" cellpadding="0"><tr><td valign="top" width="33"><div style="border: 1px dashed gray; padding-left: 5px; padding-right: 5px; margin-right: 5px; text-align: right; font-family: monospace">1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td valign="top"><pre style="margin: 0"><span style="color: #0000ff;">declare</span> <span style="color: #0000ff;font-weight:bold">function</span> callIt<span style="color: black;">&lt;</span>T<span style="color: black;">&gt;</span><span style="color: black;">&#40;</span>obj<span style="color: black;">:</span> <span style="color: black;">&#123;</span>
    produce<span style="color: black;">:</span> <span style="color: black;">&#40;</span>x<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">&#41;</span> <span style="color: black;">=&gt;</span> T<span style="color: black;">,</span>
    consume<span style="color: black;">:</span> <span style="color: black;">&#40;</span>y<span style="color: black;">:</span> T<span style="color: black;">&#41;</span> <span style="color: black;">=&gt;</span> <span style="color: #0080ff;">void</span><span style="color: black;">,</span>
<span style="color: black;">&#125;</span><span style="color: black;">&#41;</span><span style="color: black;">:</span> <span style="color: #0080ff;">void</span><span style="color: black;">;</span>
&nbsp;
<span style="color: #808080;">// Works, no issues.</span>
callIt<span style="color: black;">&#40;</span><span style="color: black;">&#123;</span>
    produce<span style="color: black;">:</span> <span style="color: black;">&#40;</span>x<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">&#41;</span> <span style="color: black;">=&gt;</span> x <span style="color: black;">*</span> <span style="color: #cc66cc;">2</span><span style="color: black;">,</span>
    consume<span style="color: black;">:</span> y <span style="color: black;">=&gt;</span> y.<span style="color: #0080ff;">toFixed</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">,</span>
<span style="color: black;">&#125;</span><span style="color: black;">&#41;</span><span style="color: black;">;</span>
&nbsp;
<span style="color: #808080;">// Works, no issues even though the order of the properties is flipped.</span>
callIt<span style="color: black;">&#40;</span><span style="color: black;">&#123;</span>
    consume<span style="color: black;">:</span> y <span style="color: black;">=&gt;</span> y.<span style="color: #0080ff;">toFixed</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">,</span>
    produce<span style="color: black;">:</span> <span style="color: black;">&#40;</span>x<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">&#41;</span> <span style="color: black;">=&gt;</span> x <span style="color: black;">*</span> <span style="color: #cc66cc;">2</span><span style="color: black;">,</span>
<span style="color: black;">&#125;</span><span style="color: black;">&#41;</span><span style="color: black;">;</span></pre></td></tr></table></code><hr />
</div><br />
<br />
<br />
Ici, TypeScript peut déduire le type de <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">y</span> dans la fonction <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">consume</span> en se basant sur le type <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">T</span> déduit de la fonction <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">produce</span>, quel que soit l'ordre des propriétés. Mais qu'en est-il si ces fonctions ont été écrites en utilisant la syntaxe de méthode plutôt que la syntaxe de fonction fléchée ?<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><table cellspacing="0" cellpadding="0"><tr><td valign="top" width="33"><div style="border: 1px dashed gray; padding-left: 5px; padding-right: 5px; margin-right: 5px; text-align: right; font-family: monospace">1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br /></div></td><td valign="top"><pre style="margin: 0"><span style="color: #0000ff;">declare</span> <span style="color: #0000ff;font-weight:bold">function</span> callIt<span style="color: black;">&lt;</span>T<span style="color: black;">&gt;</span><span style="color: black;">&#40;</span>obj<span style="color: black;">:</span> <span style="color: black;">&#123;</span>
    produce<span style="color: black;">:</span> <span style="color: black;">&#40;</span>x<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">&#41;</span> <span style="color: black;">=&gt;</span> T<span style="color: black;">,</span>
    consume<span style="color: black;">:</span> <span style="color: black;">&#40;</span>y<span style="color: black;">:</span> T<span style="color: black;">&#41;</span> <span style="color: black;">=&gt;</span> <span style="color: #0080ff;">void</span><span style="color: black;">,</span>
<span style="color: black;">&#125;</span><span style="color: black;">&#41;</span><span style="color: black;">:</span> <span style="color: #0080ff;">void</span><span style="color: black;">;</span>
&nbsp;
<span style="color: #808080;">// Works fine, `x` is inferred to be a number.</span>
callIt<span style="color: black;">&#40;</span><span style="color: black;">&#123;</span>
    produce<span style="color: black;">&#40;</span>x<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">&#41;</span> <span style="color: black;">&#123;</span> <span style="color: #0000ff;">return</span> x <span style="color: black;">*</span> <span style="color: #cc66cc;">2</span><span style="color: black;">;</span> <span style="color: black;">&#125;</span><span style="color: black;">,</span>
    consume<span style="color: black;">&#40;</span>y<span style="color: black;">&#41;</span> <span style="color: black;">&#123;</span> <span style="color: #0000ff;">return</span> y.<span style="color: #0080ff;">toFixed</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">;</span> <span style="color: black;">&#125;</span><span style="color: black;">,</span>
<span style="color: black;">&#125;</span><span style="color: black;">&#41;</span><span style="color: black;">;</span>
&nbsp;
callIt<span style="color: black;">&#40;</span><span style="color: black;">&#123;</span>
    consume<span style="color: black;">&#40;</span>y<span style="color: black;">&#41;</span> <span style="color: black;">&#123;</span> <span style="color: #0000ff;">return</span> y.<span style="color: #0080ff;">toFixed</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">;</span> <span style="color: black;">&#125;</span><span style="color: black;">,</span>
    <span style="color: #808080;">//                  ~</span>
    <span style="color: #808080;">// error: 'y' is of type 'unknown'.</span>
&nbsp;
    produce<span style="color: black;">&#40;</span>x<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">&#41;</span> <span style="color: black;">&#123;</span> <span style="color: #0000ff;">return</span> x <span style="color: black;">*</span> <span style="color: #cc66cc;">2</span><span style="color: black;">;</span> <span style="color: black;">&#125;</span><span style="color: black;">,</span>
<span style="color: black;">&#125;</span><span style="color: black;">&#41;</span><span style="color: black;">;</span></pre></td></tr></table></code><hr />
</div><br />
<br />
<br />
Curieusement, le deuxième appel à <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">callIt</span> génère une erreur, car TypeScript n'est pas en mesure de déduire le type de y dans la méthode <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">consume</span>. Ce qui se passe ici, c'est que lorsque TypeScript essaie de trouver des candidats pour <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">T</span>, il ignore d'abord les fonctions dont les paramètres n'ont pas de types explicites. Il procède ainsi parce que certaines fonctions peuvent avoir besoin que le type déduit de <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">T</span> soit correctement vérifié. Dans ce cas, on a besoin de connaître le type de <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">T</span> pour analyser la fonction <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">consume</span>.<br />
<br />
Ces fonctions sont appelées fonctions sensibles au contexte, c'est-à-dire des fonctions dont les paramètres n'ont pas de types explicites. Au final, le système de types devra déterminer les types de ces paramètres, mais cela va à l'encontre du fonctionnement de l'inférence dans les fonctions génériques, car les deux « tirent » les types dans des directions différentes.<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><table cellspacing="0" cellpadding="0"><tr><td valign="top" width="26"><div style="border: 1px dashed gray; padding-left: 5px; padding-right: 5px; margin-right: 5px; text-align: right; font-family: monospace">1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td valign="top"><pre style="margin: 0"><span style="color: #0000ff;font-weight:bold">function</span> callFunc<span style="color: black;">&lt;</span>T<span style="color: black;">&gt;</span><span style="color: black;">&#40;</span>callback<span style="color: black;">:</span> <span style="color: black;">&#40;</span>x<span style="color: black;">:</span> T<span style="color: black;">&#41;</span> <span style="color: black;">=&gt;</span> <span style="color: #0080ff;">void</span><span style="color: black;">,</span> value<span style="color: black;">:</span> T<span style="color: black;">&#41;</span> <span style="color: black;">&#123;</span>
    <span style="color: #0000ff;">return</span> callback<span style="color: black;">&#40;</span>value<span style="color: black;">&#41;</span><span style="color: black;">;</span>
<span style="color: black;">&#125;</span>
&nbsp;
callFunc<span style="color: black;">&#40;</span>x <span style="color: black;">=&gt;</span> x.<span style="color: #0080ff;">toFixed</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">,</span> <span style="color: #cc66cc;">42</span><span style="color: black;">&#41;</span><span style="color: black;">;</span>
<span style="color: #808080;">//       ^</span>
<span style="color: #808080;">// We need to figure out the type of `x` here,</span>
<span style="color: #808080;">// but we also need to figure out the type of `T` to check the callback.</span></pre></td></tr></table></code><hr />
</div><br />
<br />
<br />
Pour résoudre ce problème, TypeScript ignore les fonctions sensibles au contexte lors de l'inférence des arguments de type et vérifie et infère d'abord à partir d'autres arguments. Si le fait d'ignorer les fonctions sensibles au contexte ne fonctionne pas, l'inférence se poursuit simplement sur tous les arguments non vérifiés, en allant de gauche à droite dans la liste des arguments. Dans l'exemple ci-dessus, TypeScript ignorera le rappel lors de l'inférence pour <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">T</span>, mais examinera ensuite le deuxième argument, <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: #cc66cc;">42</span></span>, et en déduira que <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">T</span> est un nombre. Ensuite, lorsqu'il reviendra vérifier le rappel, il aura un type contextuel de <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">&#40;</span>x<span style="color: black;">:</span> nombre<span style="color: black;">&#41;</span> <span style="color: black;">=&gt;</span> <span style="color: #0080ff;">void</span></span>, ce qui lui permettra de déduire que x est également un nombre.<br />
<br />
Que se passe-t-il donc dans nos exemples précédents ?<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><table cellspacing="0" cellpadding="0"><tr><td valign="top" width="33"><div style="border: 1px dashed gray; padding-left: 5px; padding-right: 5px; margin-right: 5px; text-align: right; font-family: monospace">1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td valign="top"><pre style="margin: 0"><span style="color: #808080;">// Arrow syntax - no errors.</span>
callIt<span style="color: black;">&#40;</span><span style="color: black;">&#123;</span>
    consume<span style="color: black;">:</span> y <span style="color: black;">=&gt;</span> y.<span style="color: #0080ff;">toFixed</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">,</span>
    produce<span style="color: black;">:</span> <span style="color: black;">&#40;</span>x<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">&#41;</span> <span style="color: black;">=&gt;</span> x <span style="color: black;">*</span> <span style="color: #cc66cc;">2</span><span style="color: black;">,</span>
<span style="color: black;">&#125;</span><span style="color: black;">&#41;</span><span style="color: black;">;</span>
&nbsp;
<span style="color: #808080;">// Method syntax - errors!</span>
callIt<span style="color: black;">&#40;</span><span style="color: black;">&#123;</span>
    consume<span style="color: black;">&#40;</span>y<span style="color: black;">&#41;</span> <span style="color: black;">&#123;</span> <span style="color: #0000ff;">return</span> y.<span style="color: #0080ff;">toFixed</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">;</span> <span style="color: black;">&#125;</span><span style="color: black;">,</span>
    <span style="color: #808080;">//                  ~</span>
    <span style="color: #808080;">// error: 'y' is of type 'unknown'.</span>
&nbsp;
    produce<span style="color: black;">&#40;</span>x<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">&#41;</span> <span style="color: black;">&#123;</span> <span style="color: #0000ff;">return</span> x <span style="color: black;">*</span> <span style="color: #cc66cc;">2</span><span style="color: black;">;</span> <span style="color: black;">&#125;</span><span style="color: black;">,</span>
<span style="color: black;">&#125;</span><span style="color: black;">&#41;</span><span style="color: black;">;</span></pre></td></tr></table></code><hr />
</div><br />
<br />
<br />
Dans les deux exemples, une fonction avec un paramètre x explicitement typé est attribuée à <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">produce</span>. Ne devraient-ils pas être vérifiés de manière identique ?<br />
<br />
La question est subtile : la plupart des fonctions (comme celles qui utilisent la syntaxe de méthode) ont un paramètre <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: #0000ff;font-weight:bold">this</span></span> implicite, mais ce n'est pas le cas des fonctions fléchées. Toute utilisation de <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: #0000ff;font-weight:bold">this</span></span> pourrait nécessiter de « tirer » sur le type de <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">T</span>. Par exemple, connaître le type de l'objet littéral contenant pourrait à son tour nécessiter le type de <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">consume</span>, qui utilise <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">T</span>.<br />
<br />
Mais nous n'utilisons pas <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: #0000ff;font-weight:bold">this</span></span> ! Bien sûr, la fonction peut avoir une valeur <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: #0000ff;font-weight:bold">this</span></span> lors de l'exécution, mais elle n'est jamais utilisée !<br />
<br />
TypeScript 6.0 en tient compte lorsqu'il décide si une fonction est sensible au contexte ou non. Si this n'est jamais réellement utilisé dans une fonction, alors il n'est pas considéré comme sensible au contexte. Cela signifie que ces fonctions seront considérées comme ayant une priorité plus élevée en matière d'inférence de type, et tous nos exemples ci-dessus fonctionnent désormais !<br />
<br />
<b><font size="3">Importations de sous-chemins commençant par #/</font></b><br />
<br />
Lorsque Node.js a ajouté la prise en charge des modules, il a ajouté une fonctionnalité appelée « importations de sous-chemins ». Il s'agit essentiellement d'un champ appelé imports qui permet aux paquets de créer des alias internes pour les modules au sein de leur paquet.<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><table cellspacing="0" cellpadding="0"><tr><td valign="top" width="26"><div style="border: 1px dashed gray; padding-left: 5px; padding-right: 5px; margin-right: 5px; text-align: right; font-family: monospace">1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td valign="top"><pre style="margin: 0"><span style="color: black;">&#123;</span>
    <span style="color: #FF0000;">&quot;name&quot;</span><span style="color: black;">:</span> <span style="color: #FF0000;">&quot;my-package&quot;</span><span style="color: black;">,</span>
    <span style="color: #FF0000;">&quot;type&quot;</span><span style="color: black;">:</span> <span style="color: #FF0000;">&quot;module&quot;</span><span style="color: black;">,</span>
    <span style="color: #FF0000;">&quot;imports&quot;</span><span style="color: black;">:</span> <span style="color: black;">&#123;</span>
        <span style="color: #FF0000;">&quot;#root&quot;</span><span style="color: black;">:</span> <span style="color: #FF0000;">&quot;./dist/index.js&quot;</span><span style="color: black;">,</span>
        <span style="color: #FF0000;">&quot;#root/*&quot;</span><span style="color: black;">:</span> <span style="color: #FF0000;">&quot;./dist/*&quot;</span>
    <span style="color: black;">&#125;</span>
<span style="color: black;">&#125;</span></pre></td></tr></table></code><hr />
</div><br />
<br />
<br />
Cela permet aux modules de <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">my<span style="color: black;">-</span><span style="color: #0000ff;">package</span></span> d'importer à partir de <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">#root</span> au lieu d'avoir à utiliser un chemin relatif comme <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">..<span style="color: black;">/</span>..<span style="color: black;">/</span>index.<span style="color: #0080ff;">js</span></span>, et permet essentiellement à tout autre module d'écrire quelque chose comme<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><span style="color: #0000ff;">import</span> <span style="color: black;">*</span> <span style="color: #0000ff;font-weight:bold">as</span> utils <span style="color: #0000ff;">from</span> <span style="color: #FF0000;">&quot;#root/utils.js&quot;</span><span style="color: black;">;</span></code><hr />
</div><br />
<br />
<br />
au lieu d'utiliser un chemin relatif comme celui-ci.<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><span style="color: #0000ff;">import</span> <span style="color: black;">*</span> <span style="color: #0000ff;font-weight:bold">as</span> utils <span style="color: #0000ff;">from</span> <span style="color: #FF0000;">&quot;../../utils.js&quot;</span><span style="color: black;">;</span></code><hr />
</div><br />
<br />
<br />
Un inconvénient mineur de cette fonctionnalité est que les développeurs devaient toujours écrire quelque chose après le <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">#</span> lorsqu'ils spécifiaient une importation de sous-chemin. Ici, on utilise <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">root</span>, mais cela est un peu inutile puisqu'il n'y a pas d'autre répertoire que <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">.<span style="color: black;">/</span>dist<span style="color: black;">/</span></span> sur lequel nous effectuons le mappage.<br />
<br />
Les développeurs qui ont utilisé des bundlers sont également habitués à utiliser le mappage de chemins pour éviter les longs chemins relatifs. Une convention courante avec les bundlers consiste à utiliser un simple <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">@/</span></span> comme préfixe. Malheureusement, les importations de sous-chemins ne pouvaient pas commencer par <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">#<span style="color: black;">/</span></span>, ce qui causait beaucoup de confusion pour les développeurs qui essayaient de les adopter dans leurs projets.<br />
<br />
Mais plus récemment, Node.js a ajouté la prise en charge des importations de sous-chemins commençant par <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">#<span style="color: black;">/</span></span>. Cela permet aux paquets d'utiliser un simple préfixe <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">#<span style="color: black;">/</span></span> pour leurs importations de sous-chemins sans avoir à ajouter de segment supplémentaire.<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><table cellspacing="0" cellpadding="0"><tr><td valign="top" width="26"><div style="border: 1px dashed gray; padding-left: 5px; padding-right: 5px; margin-right: 5px; text-align: right; font-family: monospace">1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td valign="top"><pre style="margin: 0"><span style="color: black;">&#123;</span>
    <span style="color: #FF0000;">&quot;name&quot;</span><span style="color: black;">:</span> <span style="color: #FF0000;">&quot;my-package&quot;</span><span style="color: black;">,</span>
    <span style="color: #FF0000;">&quot;type&quot;</span><span style="color: black;">:</span> <span style="color: #FF0000;">&quot;module&quot;</span><span style="color: black;">,</span>
    <span style="color: #FF0000;">&quot;imports&quot;</span><span style="color: black;">:</span> <span style="color: black;">&#123;</span>
        <span style="color: #FF0000;">&quot;#&quot;</span><span style="color: black;">:</span> <span style="color: #FF0000;">&quot;./dist/index.js&quot;</span><span style="color: black;">,</span>
        <span style="color: #FF0000;">&quot;#/*&quot;</span><span style="color: black;">:</span> <span style="color: #FF0000;">&quot;./dist/*&quot;</span>
    <span style="color: black;">&#125;</span>
<span style="color: black;">&#125;</span></pre></td></tr></table></code><hr />
</div><br />
<br />
<br />
Cette fonctionnalité est prise en charge dans les nouvelles versions de Node.js 20. TypeScript la prend donc désormais en charge dans les options <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">node20</span>, <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">nodenext</span> et <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">bundler</span> pour le paramètre <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span>moduleResolution</span>.<br />
<br />
<b><font size="3">Combinaison de --moduleResolution bundler avec --module commonjs</font></b><br />
<br />
Le paramètre <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span>moduleResolution bundler</span> de TypeScript ne pouvait auparavant être utilisé qu'avec <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span><span style="color: #0000ff;font-weight:bold">module</span> esnext</span> ou <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span><span style="color: #0000ff;font-weight:bold">module</span> preserve</span> ; cependant, avec la dépréciation du nœud <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span>moduleResolution</span> (alias <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span>moduleResolution node10</span>), cette nouvelle combinaison est souvent la voie de mise à niveau la plus appropriée pour de nombreux projets.<br />
<br />
Les projets voudront souvent planifier une migration vers l'un des deux éléments suivants<br />
<br />
- <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span><span style="color: #0000ff;font-weight:bold">module</span> preserve</span> et <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span>moduleResolution bundler</span>.<br />
- <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span><span style="color: #0000ff;font-weight:bold">module</span> nodenext</span>.<br />
<br />
en fonction du type de projet (par exemple, application web groupée, application Bun ou application Node.js).<br />
<br />
<b><font size="3">Le drapeau --stableTypeOrdering</font></b><br />
<br />
Dans le cadre du travail continu sur le portage natif de TypeScript, l'équipe de typeScprit a introduit un nouveau drapeau appelé <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span>stableTypeOrdering</span> destiné à faciliter les migrations de la version 6.0 à la version 7.0.<br />
<br />
Aujourd'hui, TypeScript attribue des identifiants de type (numéros de suivi internes) aux types dans l'ordre où ils apparaissent, et utilise ces identifiants pour trier les types d'union de manière cohérente. Un processus similaire s'applique aux propriétés. Par conséquent, l'ordre dans lequel les éléments sont déclarés dans un programme peut avoir des effets surprenants sur des éléments tels que l'émission de déclarations.<br />
<br />
Prenons par exemple l'émission de déclarations à partir de ce fichier :<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><table cellspacing="0" cellpadding="0"><tr><td valign="top" width="26"><div style="border: 1px dashed gray; padding-left: 5px; padding-right: 5px; margin-right: 5px; text-align: right; font-family: monospace">1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td valign="top"><pre style="margin: 0"><span style="color: #808080;">// Input: some-file.ts</span>
<span style="color: #0000ff;font-weight:bold">export</span> <span style="color: #0000ff;font-weight:bold">function</span> foo<span style="color: black;">&#40;</span>condition<span style="color: black;">:</span> <span style="color: #0080ff;">boolean</span><span style="color: black;">&#41;</span> <span style="color: black;">&#123;</span>
    <span style="color: #0000ff;">return</span> condition <span style="color: black;">?</span> <span style="color: #cc66cc;">100</span> <span style="color: black;">:</span> <span style="color: #cc66cc;">500</span><span style="color: black;">;</span>
<span style="color: black;">&#125;</span>
&nbsp;
<span style="color: #808080;">// Output: some-file.d.ts</span>
<span style="color: #0000ff;font-weight:bold">export</span> <span style="color: #0000ff;">declare</span> <span style="color: #0000ff;font-weight:bold">function</span> foo<span style="color: black;">&#40;</span>condition<span style="color: black;">:</span> <span style="color: #0080ff;">boolean</span><span style="color: black;">&#41;</span><span style="color: black;">:</span> <span style="color: #cc66cc;">100</span> <span style="color: black;">|</span> <span style="color: #cc66cc;">500</span><span style="color: black;">;</span>
<span style="color: #808080;">//                                               ^^^^^^^^^</span>
<span style="color: #808080;">//             Note the order of this union: 100, then 500.</span></pre></td></tr></table></code><hr />
</div><br />
<br />
<br />
Si nous ajoutons une constante non liée au-dessus de <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">foo</span>, la déclaration émise change :<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><table cellspacing="0" cellpadding="0"><tr><td valign="top" width="33"><div style="border: 1px dashed gray; padding-left: 5px; padding-right: 5px; margin-right: 5px; text-align: right; font-family: monospace">1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td valign="top"><pre style="margin: 0"><span style="color: #808080;">// Input: some-file.ts</span>
<span style="color: #0000ff;font-weight:bold">const</span> x <span style="color: black;">=</span> <span style="color: #cc66cc;">500</span><span style="color: black;">;</span>
<span style="color: #0000ff;font-weight:bold">export</span> <span style="color: #0000ff;font-weight:bold">function</span> foo<span style="color: black;">&#40;</span>condition<span style="color: black;">:</span> <span style="color: #0080ff;">boolean</span><span style="color: black;">&#41;</span> <span style="color: black;">&#123;</span>
    <span style="color: #0000ff;">return</span> condition <span style="color: black;">?</span> <span style="color: #cc66cc;">100</span> <span style="color: black;">:</span> <span style="color: #cc66cc;">500</span><span style="color: black;">;</span>
<span style="color: black;">&#125;</span>
&nbsp;
<span style="color: #808080;">// Output: some-file.d.ts</span>
<span style="color: #0000ff;font-weight:bold">export</span> <span style="color: #0000ff;">declare</span> <span style="color: #0000ff;font-weight:bold">function</span> foo<span style="color: black;">&#40;</span>condition<span style="color: black;">:</span> <span style="color: #0080ff;">boolean</span><span style="color: black;">&#41;</span><span style="color: black;">:</span> <span style="color: #cc66cc;">500</span> <span style="color: black;">|</span> <span style="color: #cc66cc;">100</span><span style="color: black;">;</span>
<span style="color: #808080;">//                                               ^^^^^^^^^</span>
<span style="color: #808080;">//                           Note the change in order here.</span></pre></td></tr></table></code><hr />
</div><br />
<br />
<br />
Cela se produit parce que le type littéral <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: #cc66cc;">500</span></span> obtient un ID de type inférieur à <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: #cc66cc;">100</span></span>, car il a été traité en premier lors de l'analyse de la déclaration de la <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: #0000ff;font-weight:bold">const</span> x</span>. Dans de très rares cas, ce changement d'ordre peut même entraîner l'apparition ou la disparition d'erreurs en fonction de l'ordre de traitement du programme, mais en général, c'est principalement dans les fichiers de déclaration émis ou dans la façon dont les types sont affichés dans votre éditeur que vous remarquerez cet ordre.<br />
<br />
L'une des principales améliorations architecturales de TypeScript 7 est la vérification parallèle des types, qui réduit considérablement le temps de vérification global. Cependant, le parallélisme pose un défi : lorsque différents vérificateurs de types visitent les nœuds, les types et les symboles dans des ordres différents, les identifiants internes attribués à ces constructions deviennent non déterministes. Cela conduit à des résultats non déterministes prêtant à confusion, où deux fichiers au contenu identique dans le même programme peuvent produire des fichiers de déclaration différents, voire calculer des erreurs différentes lors de l'analyse du même fichier. Pour remédier à cela, TypeScript 7.0 trie ses objets internes (par exemple, les types et les symboles) selon un algorithme déterministe basé sur le contenu de l'objet. Cela garantit que tous les vérificateurs rencontrent le même ordre d'objets, indépendamment de la manière et du moment où ils ont été créés. En conséquence, dans l'exemple donné, TypeScript 7 affichera toujours <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: #cc66cc;">100</span> <span style="color: black;">|</span> <span style="color: #cc66cc;">500</span></span>, supprimant ainsi complètement l'instabilité de l'ordre.<br />
<br />
Cela signifie que TypeScript 6 et 7 peuvent parfois afficher un ordre différent. Bien que ces changements d'ordre soient presque toujours bénins, si vous comparez les résultats du compilateur entre deux exécutions (par exemple, en vérifiant les fichiers de déclaration émis dans 6.0 par rapport à 7.0), ces différents ordres peuvent produire beaucoup de bruit, ce qui rend difficile l'évaluation de l'exactitude. Parfois, cependant, vous pouvez constater un changement dans l'ordre qui provoque l'apparition ou la disparition d'une erreur de type, ce qui peut être encore plus déroutant.<br />
<br />
Pour remédier à cette situation, dans la version 6.0, vous pouvez spécifier le nouveau drapeau <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span>stableTypeOrdering</span>. Cela permet d'aligner le comportement de classement des types de la version 6.0 sur celui de la version 7.0, réduisant ainsi le nombre de différences entre les deux bases de code. Notez qu'il n'est pas nécessairement recommandé d'utiliser ce drapeau en permanence, car il peut ralentir considérablement la vérification des types (jusqu'à 25 % selon la base de code).<br />
<br />
Si vous rencontrez une erreur de type en utilisant [c]--stableTypeOrdering[c], cela est généralement dû à des différences d'inférence. L'inférence précédente sans <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span>stableTypeOrdering</span> fonctionnait sur la base de l'ordre actuel des types dans votre programme. Pour remédier à cela, il est souvent utile de fournir un type explicite quelque part. Il s'agira souvent d'un argument de type<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><table cellspacing="0" cellpadding="0"><tr><td valign="top" width="26"><div style="border: 1px dashed gray; padding-left: 5px; padding-right: 5px; margin-right: 5px; text-align: right; font-family: monospace">1<br />2<br /></div></td><td valign="top"><pre style="margin: 0"><span style="color: black;">-</span> someFunctionCall<span style="color: black;">&#40;</span><span style="color: #808080;">/*...*/</span><span style="color: black;">&#41;</span><span style="color: black;">;</span>
<span style="color: black;">+</span> someFunctionCall<span style="color: black;">&lt;</span>SomeExplicitType<span style="color: black;">&gt;</span><span style="color: black;">&#40;</span><span style="color: #808080;">/*...*/</span><span style="color: black;">&#41;</span><span style="color: black;">;</span></pre></td></tr></table></code><hr />
</div><br />
<br />
<br />
ou d'une annotation de variable pour un argument que vous avez l'intention de passer dans un appel.<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><table cellspacing="0" cellpadding="0"><tr><td valign="top" width="26"><div style="border: 1px dashed gray; padding-left: 5px; padding-right: 5px; margin-right: 5px; text-align: right; font-family: monospace">1<br />2<br />3<br />4<br /></div></td><td valign="top"><pre style="margin: 0"><span style="color: black;">-</span> <span style="color: #0000ff;font-weight:bold">const</span> someVariable <span style="color: black;">=</span> <span style="color: black;">&#123;</span> <span style="color: #808080;">/*... some complex object ...*/</span> <span style="color: black;">&#125;</span><span style="color: black;">;</span>
<span style="color: black;">+</span> <span style="color: #0000ff;font-weight:bold">const</span> someVariable<span style="color: black;">:</span> SomeExplicitType <span style="color: black;">=</span> <span style="color: black;">&#123;</span> <span style="color: #808080;">/*... some complex object ...*/</span> <span style="color: black;">&#125;</span><span style="color: black;">;</span>
&nbsp;
someFunctionCall<span style="color: black;">&#40;</span>someVariable<span style="color: black;">&#41;</span><span style="color: black;">;</span></pre></td></tr></table></code><hr />
</div><br />
<br />
<br />
Notez que cet indicateur est uniquement destiné à aider à diagnostiquer les différences entre les versions 6.0 et 7.0. Il n'est pas destiné à être utilisé comme fonctionnalité à long terme.<br />
<br />
<b><font size="3">Option es2025 pour target et lib</font></b><br />
<br />
TypeScript 6.0 ajoute la prise en charge de l'option <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">es2025</span> pour <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">target</span> et <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">lib</span>. Bien qu'il n'y ait pas de nouvelles fonctionnalités du langage JavaScript dans ES2025, cette nouvelle cible ajoute de nouveaux types pour les API intégrées (par exemple <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: #0080ff;">RegExp</span>.<span style="color: #339933;">escape</span></span>) et déplace quelques déclarations de <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">esnext</span> vers <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">es2025</span> (par exemple <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">Promise.<span style="color: #0000ff;">try</span></span>, les méthodes <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">Iterator</span> et les méthodes <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">Set</span>). <br />
<br />
<b><font size="3">Nouveaux types pour Temporal</font></b><br />
<br />
La proposition Temporal tant attendue a atteint la phase 3 et devrait être ajoutée à JavaScript dans un avenir proche. TypeScript 6.0 inclut désormais des types intégrés pour l'API Temporal, vous pouvez donc commencer à l'utiliser dès aujourd'hui dans votre code TypeScript via <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span>target esnext</span> ou <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: #FF0000;">&quot;lib&quot;</span> <span style="color: black;">:</span> <span style="color: black;">&#91;</span><span style="color: #FF0000;">&quot;esnext&quot;</span><span style="color: black;">&#93;</span></span> (ou le plus granulaire <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">temporal.<span style="color: #0080ff;">esnext</span></span>).<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><table cellspacing="0" cellpadding="0"><tr><td valign="top" width="33"><div style="border: 1px dashed gray; padding-left: 5px; padding-right: 5px; margin-right: 5px; text-align: right; font-family: monospace">1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td valign="top"><pre style="margin: 0"><span style="color: #0000ff;font-weight:bold">let</span> yesterday <span style="color: black;">=</span> Temporal.<span style="color: #0080ff;">Now</span>.<span style="color: #0080ff;">instant</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: #0080ff;">subtract</span><span style="color: black;">&#40;</span><span style="color: black;">&#123;</span>
    hours<span style="color: black;">:</span> <span style="color: #cc66cc;">24</span><span style="color: black;">,</span>
<span style="color: black;">&#125;</span><span style="color: black;">&#41;</span><span style="color: black;">;</span>
&nbsp;
<span style="color: #0000ff;font-weight:bold">let</span> tomorrow <span style="color: black;">=</span> Temporal.<span style="color: #0080ff;">Now</span>.<span style="color: #0080ff;">instant</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: #0080ff;">add</span><span style="color: black;">&#40;</span><span style="color: black;">&#123;</span>
    hours<span style="color: black;">:</span> <span style="color: #cc66cc;">24</span><span style="color: black;">,</span>
<span style="color: black;">&#125;</span><span style="color: black;">&#41;</span><span style="color: black;">;</span>
&nbsp;
console.<span style="color: #0080ff;">log</span><span style="color: black;">&#40;</span><span style="color: #FF0000;">`Yesterday: <span style="color: #800000;">${yesterday}</span>`</span><span style="color: black;">&#41;</span><span style="color: black;">;</span>
console.<span style="color: #0080ff;">log</span><span style="color: black;">&#40;</span><span style="color: #FF0000;">`Tomorrow: <span style="color: #800000;">${tomorrow}</span>`</span><span style="color: black;">&#41;</span><span style="color: black;">;</span></pre></td></tr></table></code><hr />
</div><br />
<br />
<br />
Temporal est déjà utilisable dans plusieurs environnements d'exécution, vous devriez donc pouvoir commencer à l'expérimenter rapidement.<br />
<br />
<b><font size="3">Préparation pour TypeScript 7.0</font></b><br />
<br />
TypeScript 6.0 est conçu comme une version de transition. Bien que les options obsolètes dans TypeScript 6.0 continueront de fonctionner sans erreur lorsque <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: #FF0000;">&quot;ignoreDeprecations&quot;</span> <span style="color: black;">:</span> <span style="color: #FF0000;">&quot;6.0&quot;</span></span> est défini, elles seront entièrement supprimées dans TypeScript 7.0 (le port TypeScript natif). Si vous voyez des avertissements de dépréciation après la mise à niveau vers TypeScript 6.0, il est vivement recommandé de les traiter avant d'essayer d'adopter TypeScript 7 (ou ses aperçus natifs) dans votre projet.<br />
<br />
En ce qui concerne le calendrier entre TypeScript 6.0 et 7.0, l'équipe prévoit de publier la version 7.0 peu après la version 6.0. Cela devrait aider à maintenir une certaine continuité dans le développement et permettre de résoudre les problèmes plus rapidement après la publication de la version 7.0.<br />
<br />
À ce stade, TypeScript 6.0 est « stable en termes de fonctionnalités » et il n'est pas prévu d'ajouter de nouvelles fonctionnalités ni d'apporter de modifications importantes. Au cours des prochaines semaines, ils traiteront tous les nouveaux problèmes signalés dans le code source 6.0. Ils continuent également à travailler sur TypeScript 7.0 et publiront des versions nocturnes des aperçus natifs ainsi qu'une extension VS Code. <br />
<br />
<b>Source</b> : <a rel="nofollow" href="https://devblogs.microsoft.com/typescript/announcing-typescript-6-0-beta/" target="_blank">Annonce de TypeScript 6.0 Beta</a><br />
<br />
<b>Et vous ?</b><br />
<br />
:fleche: Pensez-vous que cette annonce est crédible ou pertinente ?<br />
:fleche: Quel est votre avis sur le sujet ?<br />
<br />
<b>Voir aussi :</b><br />
<br />
:fleche: <a href="https://typescript.developpez.com/actu/374164/Microsoft-annonce-la-version-candidate-RC-de-TypeScript-5-9-apportant-des-mise-a-jour-a-tsc-moins-init-ainsi-que-la-prise-en-charge-de-import-defer-et-de-moins-module-node20/" target="_blank">Microsoft annonce la version candidate (RC) de TypeScript 5.9 apportant des mise à jour à tsc --init ainsi que la prise en charge de import defer et de --module node20</a><br />
<br />
:fleche: <a href="https://typescript.developpez.com/actu/369976/Un-TypeScript-10x-plus-rapide-Anders-Hejlsberg-architecte-principal-de-Microsoft-pour-TypeScript-presente-un-nouveau-portage-de-TypeScript-qui-offrira-aux-developpeurs-un-outil-de-haute-performance/" target="_blank">Un TypeScript 10x plus rapide : Anders Hejlsberg, architecte principal de Microsoft pour TypeScript, présente un nouveau portage de TypeScript qui offrira aux développeurs un outil de haute performance</a><br />
<br />
:fleche: <a href="https://programmation.developpez.com/actu/369946/Pourquoi-je-suis-sceptique-quant-a-la-reecriture-des-outils-JavaScript-dans-des-langages-plus-rapides-par-Nolan-Lawson/" target="_blank">Pourquoi je suis sceptique quant à la réécriture des outils JavaScript dans des langages &quot;plus rapides&quot;, par Nolan Lawson</a></div>


	<div style="padding:10px">

	

	
		<fieldset class="fieldset">
			<legend>Images attachées</legend>
				<div style="padding:10px">
				<img class="attach" src="https://www.developpez.net/forums/attachments/p674204d1770988851/javascript/typescript/microsoft-annonce-version-stable-typescript-6-0/1.jpg/" alt="" />&nbsp;
			</div>
		</fieldset>
	

	

	

	</div>
]]></content:encoded>
			<category domain="https://www.developpez.net/forums/f2001/javascript/typescript/">TypeScript</category>
			<dc:creator>Alex</dc:creator>
			<guid isPermaLink="true">https://www.developpez.net/forums/d2182070/javascript/typescript/microsoft-annonce-version-stable-typescript-6-0-a/</guid>
		</item>
		<item>
			<title><![CDATA[Contruire un object à partir d'un autre]]></title>
			<link>https://www.developpez.net/forums/showthread.php?t=2181392&amp;goto=newpost</link>
			<pubDate>Thu, 08 Jan 2026 22:34:00 GMT</pubDate>
			<description>Bonjour, 
 
Je suis sur un...</description>
			<content:encoded><![CDATA[<div>Bonjour,<br />
<br />
Je suis sur un challenge.<br />
<br />
J'ai cinq terrains disponibles, le 1 , 2, 3 , 5 ,6<br />
Ces terrains se trouvent dans un array<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><table cellspacing="0" cellpadding="0"><tr><td valign="top" width="26"><div style="border: 1px dashed gray; padding-left: 5px; padding-right: 5px; margin-right: 5px; text-align: right; font-family: monospace">1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td valign="top"><pre style="margin: 0"><span style="color: #0000ff;font-weight:bold">const</span> f<span style="color: black;">:</span><span style="color: #0080ff;">any</span> <span style="color: black;">=</span> <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
    fields.<span style="color: #0080ff;">map</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>p<span style="color: black;">&#41;</span> <span style="color: black;">=&gt;</span><span style="color: black;">&#123;</span>
      f.<span style="color: #0080ff;">push</span><span style="color: black;">&#40;</span>p.<span style="color: #0080ff;">id</span><span style="color: black;">&#41;</span>
    <span style="color: black;">&#125;</span><span style="color: black;">&#41;</span>
    console.<span style="color: #0080ff;">log</span><span style="color: black;">&#40;</span><span style="color: #FF0000;">&quot;All fields:&quot;</span><span style="color: black;">,</span>f<span style="color: black;">&#41;</span>
<span style="color: #808080;">// All fields: [&quot;1&quot;, &quot;2&quot;, &quot;4&quot;, &quot;5&quot;, &quot;6&quot;]</span></pre></td></tr></table></code><hr />
</div><br />
<br />
je veux maintenant activer 3 terrains, disons le 1, 2 et 5<br />
<br />
Je dois miantenant retourner une valeur qui indique quels terrains sont 1 ou 0 (actif, inactif) et il m'est imposé ce format, ce qui me complique la vie<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Citation:</div>
	<div class="bbcode_quote printable">
		<hr />
		
			{&quot;field1&quot;:&quot;1&quot;, &quot;filed2&quot;:&quot;1&quot;, &quot;field3&quot;:&quot;0&quot;, &quot;field4&quot;:&quot;0&quot;, &quot;field5&quot;:&quot;1&quot;}
			
		<hr />
	</div>
</div>J'ai donc commencer comme cela<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><table cellspacing="0" cellpadding="0"><tr><td valign="top" width="33"><div style="border: 1px dashed gray; padding-left: 5px; padding-right: 5px; margin-right: 5px; text-align: right; font-family: monospace">1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td valign="top"><pre style="margin: 0">&nbsp;
    <span style="color: #0000ff;font-weight:bold">const</span> tags <span style="color: black;">=</span> <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span>
&nbsp;
    f.<span style="color: #0080ff;">map</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>i<span style="color: black;">:</span><span style="color: #0080ff;">any</span><span style="color: black;">,</span> o<span style="color: black;">:</span><span style="color: #0080ff;">any</span><span style="color: black;">&#41;</span> <span style="color: black;">=&gt;</span> <span style="color: black;">&#123;</span> <span style="color: #808080;">// je loop mes terrains disponibles</span>
      <span style="color: #0000ff;">if</span><span style="color: black;">&#40;</span>selectedFields.<span style="color: #0080ff;">find</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>e<span style="color: black;">:</span><span style="color: #0080ff;">any</span><span style="color: black;">&#41;</span> <span style="color: black;">=&gt;</span> e <span style="color: black;">==</span> i.<span style="color: #0080ff;">toString</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: black;">==</span> i<span style="color: black;">&#41;</span><span style="color: black;">&#123;</span> <span style="color: #808080;">// Si l'un de mes trois terrains actifs est dans f</span>
        console.<span style="color: #0080ff;">log</span><span style="color: black;">&#40;</span>i<span style="color: black;">,</span> <span style="color: #FF0000;">&quot;IS IN ALL FIELD&quot;</span><span style="color: black;">&#41;</span>
        <span style="color: #808080;">// tags prend la valeur de {&quot;field&quot;+i.toString():&quot;1&quot;})</span>
      <span style="color: black;">&#125;</span>
      <span style="color: #0000ff;">else</span><span style="color: black;">&#123;</span> <span style="color: #808080;">// et si elle ne l'est pas, la valeur vient &agrave; 0</span>
        console.<span style="color: #0080ff;">log</span><span style="color: black;">&#40;</span>i<span style="color: black;">,</span> <span style="color: #FF0000;">&quot;is NOT in all fields&quot;</span><span style="color: black;">&#41;</span>
        <span style="color: #808080;">// tags prend la valeur de {&quot;field&quot;+i.toString():&quot;0&quot;})</span>
&nbsp;
      <span style="color: black;">&#125;</span>
    <span style="color: black;">&#125;</span><span style="color: black;">&#41;</span>
<span style="color: #808080;">// pour contruire, au fur et &agrave; mesure de la progression de map()</span>
&nbsp;
    console.<span style="color: #0080ff;">log</span><span style="color: black;">&#40;</span><span style="color: #FF0000;">&quot;TAGS&quot;</span><span style="color: black;">,</span> tags<span style="color: black;">&#41;</span> <span style="color: #808080;">// doit afficher ceci {&quot;field1&quot;:&quot;1&quot;, &quot;filed2&quot;:&quot;1&quot;, &quot;field3&quot;:&quot;0&quot;, &quot;field4&quot;:&quot;0&quot;, &quot;field5&quot;:&quot;1&quot;}</span></pre></td></tr></table></code><hr />
</div><br />
J'ai essayé avec .push, sans succès. <br />
<br />
Comment est-ce que vous le feriez?</div>

]]></content:encoded>
			<category domain="https://www.developpez.net/forums/f2001/javascript/typescript/">TypeScript</category>
			<dc:creator>pierrot10</dc:creator>
			<guid isPermaLink="true">https://www.developpez.net/forums/d2181392/javascript/typescript/contruire-object-partir-d/</guid>
		</item>
		<item>
			<title>Typer une fonction useQuery()</title>
			<link>https://www.developpez.net/forums/showthread.php?t=2181240&amp;goto=newpost</link>
			<pubDate>Wed, 31 Dec 2025 17:11:05 GMT</pubDate>
			<description>Bonjour à tous, 
 
Je vais...</description>
			<content:encoded><![CDATA[<div>Bonjour à tous,<br />
<br />
Je vais essayé d'être le plus claire possible. Je développe une App iOS/Android avec React Native et Type Script.<br />
En partant de zéro, j'ai tout appris avec le Web et Youtube.<br />
<br />
Grâce à un tuto, j'ai pu faire une fonction (solution 1) qui va faire appelle à useQuery pour extraire les données d'un base de donnée, le tout typé.<br />
J'utilise cette fonction sur trois vues. Ces trois font appelle à cette fonction et le paramètre queryKey est le même pour ces trois vues<br />
<br />
Pour un besoin, j'utilise réutilisé directement la fonction useQuery() (solutiuon 2)pour que je puisse paramètre queryKey pour une vue.<br />
Mon problème est que je n'ai pas réussi à typer ma sortie....<br />
<br />
Pour être plus précis, je vous montre <b>la solution 1</b>, afin de mieux comprendre ma question<br />
<br />
Dans ma vue setting.tsx, j'ai ceci<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><table cellspacing="0" cellpadding="0"><tr><td valign="top" width="26"><div style="border: 1px dashed gray; padding-left: 5px; padding-right: 5px; margin-right: 5px; text-align: right; font-family: monospace">1<br />2<br />3<br /></div></td><td valign="top"><pre style="margin: 0">&nbsp;
<span style="color: #0000ff;">import</span> <span style="color: black;">&#123;</span> useFetchQuery <span style="color: black;">&#125;</span> <span style="color: #0000ff;">from</span> <span style="color: #FF0000;">&quot;@/hooks/useFetchQuery&quot;</span><span style="color: black;">;</span>
<span style="color: #0000ff;font-weight:bold">const</span> <span style="color: black;">&#123;</span>data<span style="color: black;">,</span> isFetching<span style="color: black;">&#125;</span> <span style="color: black;">=</span> useFetchQuery<span style="color: black;">&#40;</span><span style="color: #FF0000;">&quot;/getsettings/[id_field]/[id_user]&quot;</span><span style="color: black;">,</span> <span style="color: black;">&#123;</span>id_field<span style="color: black;">:</span> <span style="color: #cc66cc;">0</span><span style="color: black;">,</span> id_user<span style="color: black;">:</span>id_user<span style="color: black;">&#125;</span><span style="color: black;">&#41;</span></pre></td></tr></table></code><hr />
</div><br />
Dans mon fichier useFetchQuety.ts, j'ai ceci<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><table cellspacing="0" cellpadding="0"><tr><td valign="top" width="33"><div style="border: 1px dashed gray; padding-left: 5px; padding-right: 5px; margin-right: 5px; text-align: right; font-family: monospace">1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br /></div></td><td valign="top"><pre style="margin: 0"><span style="color: #0000ff;">import</span> <span style="color: black;">&#123;</span> useInfiniteQuery<span style="color: black;">,</span> useQuery <span style="color: black;">&#125;</span> <span style="color: #0000ff;">from</span> <span style="color: #FF0000;">'@tanstack/react-query'</span>
&nbsp;
<span style="color: #0000ff;font-weight:bold">const</span> endpoint <span style="color: black;">=</span> <span style="color: #FF0000;">&quot;https://api.web.ch/dashboard&quot;</span>
&nbsp;
<span style="color: #0000ff;font-weight:bold">type</span> API <span style="color: black;">=</span> <span style="color: black;">&#123;</span>
<span style="color: #FF0000;">'/getsettings/[id_field]/[id_user]'</span><span style="color: black;">:</span> <span style="color: black;">&#123;</span>
        response<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span> 
        id_field<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span>
        method<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
        fields<span style="color: black;">:</span><span style="color: black;">&#123;</span>
            id_field<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span>
            field_name<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
            field_longname<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
            field_city<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
            field_lat<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span>
            field_lng<span style="color: black;">:</span> <span style="color: #0080ff;">number</span>
        <span style="color: black;">&#125;</span><span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><span style="color: black;">,</span>
        settings<span style="color: black;">:</span> <span style="color: black;">&#123;</span>
            id_station_type<span style="color: black;">?:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span>
            station_type_name<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
            station_type_awe<span style="color: black;">?:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
            field_data<span style="color: black;">:</span> <span style="color: black;">&#123;</span>
                id_field<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span>
                field_name<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
                field_user_role<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span>
                station_data<span style="color: black;">:</span> <span style="color: black;">&#123;</span>
                    id_station<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span>
                    station_name<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
                    station_longname<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
                    station_type_awe<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
                    station_archive<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span>
                    station_lat<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span>
                    station_lng<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span>
                    station_alt<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span>
                    sensors_data<span style="color: black;">:</span> <span style="color: black;">&#123;</span>
                        id_sensor<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span>
                        sensor_active<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span>
                        sensor_name<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
                        sensor_unit<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
                        sensor_longname<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
                        id_sensor_type<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span>
                        sensor_type_name<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
                        sensor_type_longname<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
                        sensor_type_awe<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
                        sensor_chart_style<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
                        sensor_chart_borderWidth<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
                        sensor_chart_pointRadius<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span>
                        sensor_chart_showLine<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span>
                        sensor_chart_fill<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span>
                        sensor_chart_borderColor<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
                        sensor_chart_backgroundColor<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
                        sensor_chart_pointStyle<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
                        sensor_threshold_operator<span style="color: black;">:</span><span style="color: #FF0000;">'string'</span><span style="color: black;">,</span>
                        sensor_threshold_min<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span>
                        sensor_threshold_max<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span>
&nbsp;
                    <span style="color: black;">&#125;</span><span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><span style="color: black;">,</span>
                <span style="color: black;">&#125;</span><span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><span style="color: black;">,</span>
            <span style="color: black;">&#125;</span><span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><span style="color: black;">,</span>
        <span style="color: black;">&#125;</span><span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><span style="color: black;">,</span>
    <span style="color: black;">&#125;</span>
<span style="color: black;">&#125;</span>
&nbsp;
<span style="color: #0000ff;font-weight:bold">export</span> <span style="color: #0000ff;font-weight:bold">function</span> useFetchQuery<span style="color: black;">&lt;</span>T <span style="color: #0000ff;font-weight:bold">extends</span> keyof API<span style="color: black;">&gt;</span><span style="color: black;">&#40;</span>path<span style="color: black;">:</span> T<span style="color: black;">,</span> params<span style="color: black;">?:</span> Record<span style="color: black;">&lt;</span><span style="color: #0080ff;">string</span><span style="color: black;">,</span> <span style="color: #0080ff;">string</span> <span style="color: black;">|</span> number<span style="color: black;">&gt;</span><span style="color: black;">&#41;</span><span style="color: black;">&#123;</span>
    <span style="color: #0000ff;font-weight:bold">const</span> localurl <span style="color: black;">=</span> endpoint <span style="color: black;">+</span> <span style="color: #0080ff;">Object</span>.<span style="color: #0080ff;">entries</span><span style="color: black;">&#40;</span>params <span style="color: black;">??</span> <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span><span style="color: black;">&#41;</span>.<span style="color: #0080ff;">reduce</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>acc<span style="color: black;">,</span> <span style="color: black;">&#91;</span>key<span style="color: black;">,</span> value<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> <span style="color: black;">=&gt;</span> acc.<span style="color: #0080ff;">replaceAll</span><span style="color: black;">&#40;</span><span style="color: #FF0000;">`[<span style="color: #800000;">${key}</span>]`</span><span style="color: black;">,</span> value.<span style="color: #0080ff;">toString</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #0000ff;font-weight:bold">as</span> T<span style="color: black;">,</span> path<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #808080;">//console.log(&quot;useFetchUqrey: &quot;,localurl)</span>
&nbsp;
    <span style="color: #0000ff;">return</span> useQuery<span style="color: black;">&#40;</span><span style="color: black;">&#123;</span>
        queryKey<span style="color: black;">:</span> <span style="color: black;">&#91;</span>localurl<span style="color: black;">&#93;</span><span style="color: black;">,</span>
        <span style="color: #808080;">//refetchIntervalInBackground: true,  </span>
        <span style="color: #808080;">//refetchInterval: 60000, // 60 000 ms = 60 secondes</span>
        <span style="color: #808080;">//refetchOnWindowFocus: false,</span>
        <span style="color: #808080;">//staleTime:30000,</span>
        queryFn<span style="color: black;">:</span> <span style="color: #0000ff;font-weight:bold">async</span> <span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: black;">=&gt;</span> <span style="color: black;">&#123;</span> <span style="color: #808080;">// Comment on re&eacute;cup&egrave;re les r&eacute;sultat</span>
            <span style="color: #808080;">//await wait(2);</span>
            <span style="color: #0000ff;">return</span> fetch<span style="color: black;">&#40;</span>localurl<span style="color: black;">,</span><span style="color: black;">&#123;</span>
                headers<span style="color: black;">:</span><span style="color: black;">&#123;</span>
                    Accept<span style="color: black;">:</span> <span style="color: #FF0000;">'application/json'</span><span style="color: black;">,</span>
                <span style="color: black;">&#125;</span>
            <span style="color: black;">&#125;</span><span style="color: black;">&#41;</span>.<span style="color: #0080ff;">then</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>r<span style="color: black;">&#41;</span> <span style="color: black;">=&gt;</span> r.<span style="color: #0080ff;">json</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #0000ff;font-weight:bold">as</span> Promise<span style="color: black;">&lt;</span>API<span style="color: black;">&#91;</span>T<span style="color: black;">&#93;</span><span style="color: black;">&gt;</span><span style="color: black;">&#41;</span><span style="color: black;">;</span> <span style="color: #808080;">// Convertir le r&eacute;sultat (r) en json</span>
        <span style="color: black;">&#125;</span><span style="color: black;">,</span>
    <span style="color: black;">&#125;</span><span style="color: black;">&#41;</span>
<span style="color: black;">&#125;</span></pre></td></tr></table></code><hr />
</div><br />
Le mega avantage, est que <br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><span style="color: #0000ff;font-weight:bold">const</span> <span style="color: black;">&#123;</span>data<span style="color: black;">,</span> isFetching<span style="color: black;">&#125;</span> <span style="color: black;">=</span> useFetchQuery<span style="color: black;">&#40;</span><span style="color: #FF0000;">&quot;/getsettings/[id_field]/[id_user]&quot;</span><span style="color: black;">,</span> <span style="color: black;">&#123;</span>id_field<span style="color: black;">:</span> <span style="color: #cc66cc;">0</span><span style="color: black;">,</span> id_user<span style="color: black;">:</span>id_user<span style="color: black;">&#125;</span><span style="color: black;">&#41;</span></code><hr />
</div><br />
lorsque je saisi data. , après le point il me propose toutes les possiblités qui sont défini dans API.<br />
<br />
<b>Solution 2</b><br />
Dans la solution 2, je le fais différemment. Dans ma vue [id].tsx, j'ai<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><table cellspacing="0" cellpadding="0"><tr><td valign="top" width="33"><div style="border: 1px dashed gray; padding-left: 5px; padding-right: 5px; margin-right: 5px; text-align: right; font-family: monospace">1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td valign="top"><pre style="margin: 0">&nbsp;
<span style="color: #0000ff;font-weight:bold">const</span> <span style="color: black;">&#123;</span>data<span style="color: black;">,</span> isPaused<span style="color: black;">,</span> isLoading<span style="color: black;">,</span> error<span style="color: black;">,</span> refetch<span style="color: black;">,</span> isFetching<span style="color: black;">&#125;</span><span style="color: black;">=</span> useQuery<span style="color: black;">&#40;</span><span style="color: black;">&#123;</span> <span style="color: #808080;">// Min 52 https://www.youtube.com/watch?v=bpHq_-bPkGo</span>
        queryKey<span style="color: black;">:</span> <span style="color: black;">&#91;</span><span style="color: #FF0000;">'station'</span><span style="color: black;">,</span> params.<span style="color: #0080ff;">id</span><span style="color: black;">,</span> dateRange<span style="color: black;">&#93;</span><span style="color: black;">,</span>
        queryFn<span style="color: black;">:</span> <span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: black;">=&gt;</span> fetchStation<span style="color: black;">&#40;</span>params.<span style="color: #0080ff;">id</span><span style="color: black;">,</span> dayjs<span style="color: black;">&#40;</span>dateRange.<span style="color: #0080ff;">startDate</span><span style="color: black;">&#41;</span>.<span style="color: #0080ff;">format</span><span style="color: black;">&#40;</span><span style="color: #FF0000;">&quot;YYYY-MM-DD&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">,</span> dayjs<span style="color: black;">&#40;</span>dateRange.<span style="color: #0080ff;">endDate</span><span style="color: black;">&#41;</span>.<span style="color: #0080ff;">format</span><span style="color: black;">&#40;</span><span style="color: #FF0000;">&quot;YYYY-MM-DD&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">,</span> id_user<span style="color: black;">&#41;</span><span style="color: black;">,</span>
        <span style="color: #808080;">//retryOnMount: false,</span>
        refetchInterval<span style="color: black;">:</span> <span style="color: #cc66cc;">30000</span><span style="color: black;">,</span>
        <span style="color: #808080;">//gcTime: 1000 * 60,</span>
        <span style="color: #808080;">//staleTime: 1000 * 30, // Data remains fresh for 60 sec</span>
        refetchOnWindowFocus<span style="color: black;">:</span> <span style="color: #339933;">true</span><span style="color: black;">,</span>
        <span style="color: #808080;">//enabled: false,</span>
        <span style="color: #808080;">//retry: 2, // Retry twice on failure</span>
        <span style="color: #808080;">//retryDelay: 2000, // Wait 2 seconds between retries</span>
        <span style="color: #808080;">//select: (data) =&gt; data.map((post) =&gt; post.title), // Extract only post title</span>
    <span style="color: black;">&#125;</span><span style="color: black;">&#41;</span></pre></td></tr></table></code><hr />
</div>Comme vous pouvez le voir, je peux directement paramètrer useQuery. <br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><table cellspacing="0" cellpadding="0"><tr><td valign="top" width="33"><div style="border: 1px dashed gray; padding-left: 5px; padding-right: 5px; margin-right: 5px; text-align: right; font-family: monospace">1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br /></div></td><td valign="top"><pre style="margin: 0">&nbsp;
<span style="color: #0000ff;">import</span> <span style="color: black;">&#123;</span> QueryClient<span style="color: black;">,</span> useInfiniteQuery<span style="color: black;">,</span> useQuery <span style="color: black;">&#125;</span> <span style="color: #0000ff;">from</span> <span style="color: #FF0000;">'@tanstack/react-query'</span>
&nbsp;
<span style="color: #0000ff;font-weight:bold">const</span> uri <span style="color: black;">=</span> <span style="color: #FF0000;">&quot;https://api.web.ch/dashboard&quot;</span>
<span style="color: #0000ff;font-weight:bold">const</span> endpoint <span style="color: black;">=</span> <span style="color: #FF0000;">&quot;/getstation/&quot;</span>
<span style="color: #0000ff;font-weight:bold">const</span> params <span style="color: black;">=</span> <span style="color: #FF0000;">&quot;/&quot;</span>
&nbsp;
<span style="color: #0000ff;font-weight:bold">const</span> headers <span style="color: black;">=</span> <span style="color: black;">&#123;</span>
    accept<span style="color: black;">:</span> <span style="color: #FF0000;">'application/json'</span><span style="color: black;">,</span>
    Authorisation<span style="color: black;">:</span> <span style="color: #FF0000;">'key'</span><span style="color: black;">,</span>
<span style="color: black;">&#125;</span>
&nbsp;
<span style="color: #0000ff;font-weight:bold">export</span> <span style="color: #0000ff;font-weight:bold">const</span> fetchStation <span style="color: black;">=</span> <span style="color: #0000ff;font-weight:bold">async</span> <span style="color: black;">&#40;</span>id<span style="color: black;">:</span><span style="color: #0080ff;">string</span><span style="color: black;">,</span> dateFrom<span style="color: black;">:</span><span style="color: #0080ff;">string</span><span style="color: black;">,</span> dateTo<span style="color: black;">:</span><span style="color: #0080ff;">string</span><span style="color: black;">,</span> user_id<span style="color: black;">:</span><span style="color: #0080ff;">number</span><span style="color: black;">&#41;</span> <span style="color: black;">=&gt;</span> <span style="color: black;">&#123;</span>
&nbsp;
    <span style="color: #0000ff;font-weight:bold">const</span> url <span style="color: black;">=</span> uri<span style="color: black;">+</span>endpoint<span style="color: black;">+</span>id<span style="color: black;">+</span><span style="color: #FF0000;">'/'</span><span style="color: black;">+</span>dateFrom<span style="color: black;">+</span><span style="color: #FF0000;">'/'</span><span style="color: black;">+</span>dateTo<span style="color: black;">+</span><span style="color: #FF0000;">'/'</span><span style="color: black;">+</span>user_id<span style="color: black;">+</span><span style="color: #FF0000;">'/'</span><span style="color: black;">;</span>
    <span style="color: #0000ff;font-weight:bold">const</span> options <span style="color: black;">=</span> <span style="color: black;">&#123;</span>
        method<span style="color: black;">:</span> <span style="color: #FF0000;">'GET'</span><span style="color: black;">,</span>
        headers<span style="color: black;">,</span>
    <span style="color: black;">&#125;</span><span style="color: black;">;</span>
&nbsp;
    <span style="color: #0000ff;">try</span> <span style="color: black;">&#123;</span>
        <span style="color: #0000ff;font-weight:bold">const</span> res <span style="color: black;">=</span> <span style="color: #0000ff;font-weight:bold">await</span> fetch<span style="color: black;">&#40;</span>url<span style="color: black;">,</span> options<span style="color: black;">&#41;</span><span style="color: black;">;</span>
        <span style="color: #808080;">/*</span>
<span style="color: #808080;">&nbsp;       if(!res.ok){</span>
<span style="color: #808080;">&nbsp;          throw new Error('[fetchQuery] Failed to fetch a s tation') </span>
<span style="color: #808080;">&nbsp;       }</span>
<span style="color: #808080;">&nbsp;       */</span>
        <span style="color: #0000ff;font-weight:bold">const</span> json <span style="color: black;">=</span> <span style="color: #0000ff;font-weight:bold">await</span> res.<span style="color: #0080ff;">json</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">;</span>
        <span style="color: #0000ff;">return</span> json<span style="color: black;">;</span>
&nbsp;
    <span style="color: black;">&#125;</span><span style="color: #0000ff;">catch</span><span style="color: black;">&#40;</span>err<span style="color: black;">&#41;</span><span style="color: black;">&#123;</span>
        console.<span style="color: #0080ff;">error</span><span style="color: black;">&#40;</span><span style="color: #FF0000;">'[fetchQuery] '</span> <span style="color: black;">+</span> err<span style="color: black;">&#41;</span><span style="color: black;">;</span>
    <span style="color: black;">&#125;</span>
&nbsp;
<span style="color: black;">&#125;</span><span style="color: black;">;</span></pre></td></tr></table></code><hr />
</div>queryFn fait appelle à la fonction fetchStation() qui va s'occuper de faire la requête sur ma base de données.<br />
<br />
cela fonctionne très bien, sauf que, ... dans la solution deux, je n'ai pas de typage. Docn si je fais<br />
<br />
data. , après le point j'ai pas d'option. Tout cela, parce que je n'ai pas comme dans la solution 1, le API, genre<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><table cellspacing="0" cellpadding="0"><tr><td valign="top" width="33"><div style="border: 1px dashed gray; padding-left: 5px; padding-right: 5px; margin-right: 5px; text-align: right; font-family: monospace">1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br /></div></td><td valign="top"><pre style="margin: 0">&nbsp;
<span style="color: #0000ff;font-weight:bold">type</span> API <span style="color: black;">=</span> <span style="color: black;">&#123;</span>
<span style="color: #FF0000;">'/getsettings/[id_field]/[id_user]'</span><span style="color: black;">:</span> <span style="color: black;">&#123;</span>
        response<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span> 
        id_field<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span>
        method<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
        fields<span style="color: black;">:</span><span style="color: black;">&#123;</span>
            id_field<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span>
            field_name<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
            field_longname<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
            field_city<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
            field_lat<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span>
            field_lng<span style="color: black;">:</span> <span style="color: #0080ff;">number</span>
        <span style="color: black;">&#125;</span><span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><span style="color: black;">,</span>
        settings<span style="color: black;">:</span> <span style="color: black;">&#123;</span>
            id_station_type<span style="color: black;">?:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span>
            station_type_name<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
            station_type_awe<span style="color: black;">?:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
            field_data<span style="color: black;">:</span> <span style="color: black;">&#123;</span>
                id_field<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span>
                field_name<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
                field_user_role<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span>
                station_data<span style="color: black;">:</span> <span style="color: black;">&#123;</span>
                    id_station<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span>
                    station_name<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
                    station_longname<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
                    station_type_awe<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
                    station_archive<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span>
                    station_lat<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span>
                    station_lng<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span>
                    station_alt<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span>
                    sensors_data<span style="color: black;">:</span> <span style="color: black;">&#123;</span>
                        id_sensor<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span>
                        sensor_active<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span>
                        sensor_name<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
                        sensor_unit<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
                        sensor_longname<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
                        id_sensor_type<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span>
                        sensor_type_name<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
                        sensor_type_longname<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
                        sensor_type_awe<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
                        sensor_chart_style<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
                        sensor_chart_borderWidth<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
                        sensor_chart_pointRadius<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span>
                        sensor_chart_showLine<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span>
                        sensor_chart_fill<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span>
                        sensor_chart_borderColor<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
                        sensor_chart_backgroundColor<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
                        sensor_chart_pointStyle<span style="color: black;">:</span> <span style="color: #0080ff;">string</span><span style="color: black;">,</span>
                        sensor_threshold_operator<span style="color: black;">:</span><span style="color: #FF0000;">'string'</span><span style="color: black;">,</span>
                        sensor_threshold_min<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span>
                        sensor_threshold_max<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">,</span>
&nbsp;
                    <span style="color: black;">&#125;</span><span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><span style="color: black;">,</span>
                <span style="color: black;">&#125;</span><span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><span style="color: black;">,</span>
            <span style="color: black;">&#125;</span><span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><span style="color: black;">,</span>
        <span style="color: black;">&#125;</span><span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><span style="color: black;">,</span>
    <span style="color: black;">&#125;</span>
<span style="color: black;">&#125;</span></pre></td></tr></table></code><hr />
</div><b><br />
ma question</b><br />
<br />
J'ai aucune idée, comment je peux adapter la solution 2, pour appliquer le typage, comme dans la solution 1, de manière simple.<br />
La solution 1, je l'ai écris en suivant un tuto, et ca me semble complique<br />
<br />
Auriez-vous la gentillesse de me guider et m'aider à modifier/adapter la solution 2 pour ajouter le typage?<br />
<br />
je vous remercie et je vous souhaite uen bonne année</div>

]]></content:encoded>
			<category domain="https://www.developpez.net/forums/f2001/javascript/typescript/">TypeScript</category>
			<dc:creator>pierrot10</dc:creator>
			<guid isPermaLink="true">https://www.developpez.net/forums/d2181240/javascript/typescript/typer-fonction-usequery/</guid>
		</item>
		<item>
			<title>La version 2.6 de Deno, le runtime pour JavaScript et TypeScript moderne, est disponible</title>
			<link>https://www.developpez.net/forums/showthread.php?t=2180965&amp;goto=newpost</link>
			<pubDate>Mon, 15 Dec 2025 10:51:49 GMT</pubDate>
			<description>*Deno 2.6, la dernière...</description>
			<content:encoded><![CDATA[<div><b><font size="4">Deno 2.6, la dernière version du runtime JavaScript et TypeScript moderne, est disponible avec l'outil dx, un contrôle plus granulaire des autorisations et une vérification des types TypeScript plus rapide</font></b><br />
<br />
<b>Deno 2.6, la dernière version du runtime moderne pour JavaScript et TypeScript, vient d'être publiée. Cette mise à jour introduit un nouvel outil, <i>dx</i>, qui s'aligne sur le workflow <i>npx</i> utilisé dans les projets Node.js, et offre une vérification des types TypeScript plus rapide grâce au moteur expérimental <i>tsgo</i>, écrit en langage Go. Deno 2.6 étend également la compatibilité avec Node.js, renforce la sécurité des projets grâce à un contrôle plus granulaire des autorisations et apporte plusieurs autres améliorations.</b><br />
<br />
Deno est un environnement d'exécution (runtime) pour JavaScript, TypeScript et WebAssembly basé sur le moteur JavaScript V8 et le langage de programmation Rust. Deno a été co-créé par Ryan Dahl, le créateur de Node.js, et Bert Belder. Deno assume explicitement le rôle à la fois d'environnement d'exécution et de gestionnaire de paquets au sein d'un seul exécutable, plutôt que de nécessiter un programme de gestion de paquets séparé.<br />
<br />
Deno 2.6 est la dernière mise à jour de ce runtime JavaScript et TypeScript moderne. Le nouvel outil <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">dx</span>, qui constitue l'un des points forts de cette version, permet aux développeurs d'exécuter facilement des binaires à partir de paquets npm et JSR, en s'alignant étroitement sur le workflow <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">npx</span> utilisé dans les projets Node.js. Dans le but d'accélérer le développement, Deno 2.6 intègre désormais <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">tsgo</span>, un vérificateur de types TypeScript expérimental écrit en Go, qui offre une vitesse de vérification des types nettement améliorée par rapport à l'ancien système basé sur TypeScript.<br />
<br />
Tout en apportant des changements majeurs au flux de travail, les couches de sécurité et de compatibilité de Deno ont également évolué. Cette version ajoute le drapeau <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span><span style="color: #0000ff;">require</span></span> pour précharger les modules CommonJS, renforçant ainsi la compatibilité avec les flux de travail Node.js. Le contrôle granulaire des autorisations renforce la sécurité des projets, et la sous-commande deno audit vérifie les dépendances par rapport à la base de données GitHub Common Vulnerabilities and Exposures (CVE), produisant des rapports de sécurité pour les paquets JSR et npm.<br />
<br />
<div style="text-align: center;">
<div class="video-container"><iframe class="restrain" title="YouTube video player" width="560" height="315" allowfullscreen src="//www.youtube.com/embed/KPTOo4k8-GE?wmode=transparent&amp;fs=1" frameborder="0"></iframe></div>
</div><br />
<b><font size="3">Exécuter les binaires de paquets avec dx</font></b><br />
<br />
Deno 2.6 introduit un nouvel outil, <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">dx</span>, qui est équivalent à <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">npx</span> et constitue un moyen pratique d'exécuter les binaires des paquets npm et JSR.<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><table cellspacing="0" cellpadding="0"><tr><td valign="top" width="26"><div style="border: 1px dashed gray; padding-left: 5px; padding-right: 5px; margin-right: 5px; text-align: right; font-family: monospace">1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td valign="top"><pre style="margin: 0">$ dx cowsay <span style="color: #FF0000;">&quot;Hello, Deno!&quot;</span>
 ______________
<span style="color: black;">&lt;</span> Hello<span style="color: black;">,</span> Deno<span style="color: black;">!</span> <span style="color: black;">&gt;</span>
 <span style="color: black;">--------------</span>
        \   <span style="color: black;">^</span>__<span style="color: black;">^</span>
         \  <span style="color: black;">&#40;</span>oo<span style="color: black;">&#41;</span>\_______
            <span style="color: black;">&#40;</span>__<span style="color: black;">&#41;</span>\       <span style="color: black;">&#41;</span>\<span style="color: black;">/</span>\
                <span style="color: black;">||----</span>w <span style="color: black;">|</span>
                <span style="color: black;">||</span>     <span style="color: black;">||</span></pre></td></tr></table></code><hr />
</div><br />
Les utilisateurs doivent veiller à installer l'alias <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">dx</span> : <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">deno x <span style="color: black;">--</span>install<span style="color: black;">-</span>alias</span>Les utilisateurs plus expérimentés remarqueront que <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">dx</span> fonctionne de manière similaire à <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">deno run</span>, mais avec les différences suivantes :<br />
<br />
<ul><li style=""> <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">dx</span> utilise par défaut les autorisations <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span>allow<span style="color: black;">-</span>all</span>, sauf si un autre indicateur d'autorisation est transmis.</li><li style=""> <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">dx</span> invite l'utilisateur avant de télécharger un paquet.</li><li style=""> <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">dx</span> exécute automatiquement les scripts de cycle de vie si l'utilisateur accepte l'invite susmentionnée.</li><li style=""> <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">dx</span> utilise par défaut <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">npm<span style="color: black;">:&lt;</span>nom_du_paquet<span style="color: black;">&gt;</span></span> sauf indication contraire.</li><li style=""> <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">dx</span> génère une erreur si l'utilisateur tente de l'utiliser pour exécuter un fichier local.</li></ul><br />
Avec l'ajout de <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">dx</span>, les utilisateurs devraient trouver plus facile d'exécuter les binaires des paquets de la manière habituelle. Ils peuvent profiter de la commodité de <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">npx</span> tout en tirant parti du modèle de sécurité robuste et des optimisations de performances de Deno.<br />
<br />
<b><font size="3">Contrôle plus granulaires des autorisations</font></b><br />
<br />
Cette version offre un contrôle plus granulaire des autorisations. Deno 2.6 introduit les flags <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span>ignore<span style="color: black;">-</span>read</span> et <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span>ignore<span style="color: black;">-</span>env</span>, qui permettent d'ignorer de manière sélective certaines lectures de fichiers ou certains accès à des variables d'environnement. Au lieu de générer une erreur <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">NotCapable</span>, les utilisateurs peuvent demander à Deno de renvoyer respectivement une erreur <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">NotFound</span> et <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: #339933;">undefined</span></span>.<br />
<br />
Voyons un exemple de fonctionnement :<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><table cellspacing="0" cellpadding="0"><tr><td valign="top" width="26"><div style="border: 1px dashed gray; padding-left: 5px; padding-right: 5px; margin-right: 5px; text-align: right; font-family: monospace">1<br />2<br />3<br />4<br />5<br /></div></td><td valign="top"><pre style="margin: 0"><span style="color: #0000ff;font-weight:bold">const</span> awsSecretKey <span style="color: black;">=</span> Deno.<span style="color: #0080ff;">env</span>.<span style="color: #0000ff;font-weight:bold">get</span><span style="color: black;">&#40;</span><span style="color: #FF0000;">&quot;AWS_SECRET_KEY&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">;</span>
console.<span style="color: #0080ff;">log</span><span style="color: black;">&#40;</span>awsSecretKey<span style="color: black;">&#41;</span><span style="color: black;">;</span>
&nbsp;
<span style="color: #0000ff;font-weight:bold">const</span> passwd <span style="color: black;">=</span> <span style="color: #0000ff;font-weight:bold">await</span> Deno.<span style="color: #0080ff;">readTextFile</span><span style="color: black;">&#40;</span><span style="color: #FF0000;">&quot;/etc/passwd&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">;</span>
console.<span style="color: #0080ff;">log</span><span style="color: black;">&#40;</span>passwd<span style="color: black;">&#41;</span><span style="color: black;">;</span></pre></td></tr></table></code><hr />
</div><br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><table cellspacing="0" cellpadding="0"><tr><td valign="top" width="26"><div style="border: 1px dashed gray; padding-left: 5px; padding-right: 5px; margin-right: 5px; text-align: right; font-family: monospace">1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td valign="top"><pre style="margin: 0">$ deno run <span style="color: black;">--</span>ignore<span style="color: black;">-</span>read<span style="color: black;">=/</span>etc <span style="color: black;">--</span>ignore<span style="color: black;">-</span>env<span style="color: black;">=</span>AWS_SECRET_KEY main.<span style="color: #0080ff;">ts</span>
<span style="color: #339933;">undefined</span>
error<span style="color: black;">:</span> Uncaught <span style="color: black;">&#40;</span><span style="color: #0000ff;font-weight:bold">in</span> promise<span style="color: black;">&#41;</span> NotFound<span style="color: black;">:</span> No such file or directory <span style="color: black;">&#40;</span>os error <span style="color: #cc66cc;">2</span><span style="color: black;">&#41;</span>
<span style="color: #0000ff;font-weight:bold">const</span> passwd <span style="color: black;">=</span> <span style="color: #0000ff;font-weight:bold">await</span> Deno.<span style="color: #0080ff;">readTextFile</span><span style="color: black;">&#40;</span><span style="color: #FF0000;">&quot;/etc/passwd&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">;</span>
                          <span style="color: black;">^</span>
    at <span style="color: #0080ff;">Object</span>.<span style="color: #0080ff;">readTextFile</span> <span style="color: black;">&#40;</span>ext<span style="color: black;">:</span>deno_fs<span style="color: black;">/</span><span style="color: #cc66cc;">30</span>_fs.<span style="color: #0080ff;">js</span><span style="color: black;">:</span><span style="color: #cc66cc;">799</span><span style="color: black;">:</span><span style="color: #cc66cc;">24</span><span style="color: black;">&#41;</span>
    at file<span style="color: black;">:</span><span style="color: #808080;">///dev/main.ts:4:27</span></pre></td></tr></table></code><hr />
</div><br />
Ces nouveaux indicateurs offrent davantage de flexibilité lors de l'exécution de code non fiable. Souvent, le développeur ne souhaite pas ouvrir un sandbox, mais une certaine dépendance insiste pour lire 20 variables d'environnement ou fichiers de configuration à partir de son répertoire personnel. Ces dépendances gèrent correctement les variables d'environnement ou les fichiers manquants, mais elles ne sont pas en mesure de gérer les erreurs <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">NotCapable</span> de Deno. Grâce à ces nouveaux flags, il est possible d'exécuter ce type de code sans accorder toutes les autorisations.<br />
<br />
De plus, <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">Deno.<span style="color: #0080ff;">env</span>.<span style="color: #0080ff;">toObject</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></span> fonctionne désormais avec des autorisations d'environnement partielles. Si le développeur n'accorde l'accès qu'à un sous-ensemble de variables d'environnement, <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">Deno.<span style="color: #0080ff;">env</span>.<span style="color: #0080ff;">toObject</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></span> ne renverra que les variables autorisées.<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">console.<span style="color: #0080ff;">log</span><span style="color: black;">&#40;</span>Deno.<span style="color: #0080ff;">env</span>.<span style="color: #0080ff;">toObject</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">;</span></code><hr />
</div><br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><table cellspacing="0" cellpadding="0"><tr><td valign="top" width="26"><div style="border: 1px dashed gray; padding-left: 5px; padding-right: 5px; margin-right: 5px; text-align: right; font-family: monospace">1<br />2<br /></div></td><td valign="top"><pre style="margin: 0">$ SOME_SECRET<span style="color: black;">=</span>foo deno run <span style="color: black;">--</span>allow<span style="color: black;">-</span>env<span style="color: black;">=</span>SOME_SECRET main.<span style="color: #0080ff;">ts</span>
<span style="color: black;">&#123;</span> SOME_SECRET<span style="color: black;">:</span> <span style="color: #FF0000;">&quot;foo&quot;</span> <span style="color: black;">&#125;</span></pre></td></tr></table></code><hr />
</div><br />
Cette version comprend également un courtier d'autorisations expérimental. Il s'agit d'une nouvelle fonctionnalité qui permet un contrôle avancé des autorisations grâce à un processus distinct chargé de gérer les demandes d'autorisation.<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">$ DENO_PERMISSION_BROKER_PATH<span style="color: black;">=/</span>perm_broker.<span style="color: #0080ff;">sock</span> deno run untrusted_code.<span style="color: #0080ff;">ts</span></code><hr />
</div><br />
Cela peut être utile pour les auteurs de plateformes qui souhaitent exécuter du code non fiable, mais qui disposent d'un processus de niveau supérieur pour gérer les demandes d'autorisation.<br />
<br />
Lorsque le courtier d'autorisations est actif, tous les indicateurs d'autorisation <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span>allow<span style="color: black;">-*</span></span>, <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span>deny<span style="color: black;">-*</span></span> et <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span>ignore<span style="color: black;">-*</span></span> sont ignorés, et toutes les demandes d'autorisation sont envoyées au processus du courtier à la place.<br />
<br />
<b><font size="3">Vérification des types plus rapide grâce à tsgo et aux améliorations apportées au langage serveur</font></b><br />
<br />
Deno 2.6 intègre <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">tsgo</span>, un nouveau vérificateur de types expérimental pour TypeScript écrit en Go. Ce nouveau vérificateur de types est nettement plus rapide que la précédente implémentation, qui était écrite en TypeScript.<br />
<br />
<span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">tsgo</span> peut être activé en utilisant le drapeau <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span>unstable<span style="color: black;">-</span>tsgo</span> ou la variable d'environnement <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">DENO_UNSTABLE_TSGO<span style="color: black;">=</span><span style="color: #cc66cc;">1</span></span> avec <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">deno check</span> :<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">$ deno check <span style="color: black;">--</span>unstable<span style="color: black;">-</span>tsgo main.<span style="color: #0080ff;">ts</span></code><hr />
</div><br />
L'équipe de Deno a constaté une amélioration de 2 fois la vitesse des temps de vérification des types pour les projets internes lors de l'utilisation de TSGO.<br />
<br />
Du côté de la vérification des types, plusieurs points faibles de longue date ont été corrigés. Deno est désormais plus tolérant envers les schémas d'importation non standard et les déclarations de modules ambiants nus, ce qui signifie moins d'erreurs de faux positifs lors de l'utilisation d'outils de framework ou de chargeurs de modules personnalisés.<br />
<br />
La prise en charge des options courantes de <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">tsconfig.<span style="color: #0080ff;">json</span></span> a également été améliorée :<br />
<br />
<ul><li style=""> <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">compilerOptions.<span style="color: #0080ff;">paths</span></span> fonctionne désormais comme prévu pour la résolution des modules,</li><li style=""> <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">skipLibCheck</span> est respecté pour les erreurs de graphe,</li><li style=""> les paramètres avancés tels que <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">isolatedDeclarations</span> sont pris en charge.</li></ul><br />
Ces améliorations contribuent à une expérience de vérification plus prévisible, en particulier dans les espaces de travail multi-paquets.<br />
<br />
Le langage serveur (LSP) a également bénéficié de quelques améliorations en termes de qualité de vie. L'action <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">source.<span style="color: #0080ff;">organizeImports</span></span> est désormais prise en charge, ce qui permet de trier et de nettoyer automatiquement les importations depuis l'éditeur. Deno utilisera l'implémentation native de l'éditeur lorsqu'elle est disponible et évitera tout travail de résolution inutile, rendant ainsi la fonctionnalité plus intuitive. La création de tests est également améliorée grâce à une meilleure intégration des fonctions de test du style <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">describe</span> et <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">it</span>. Les éditeurs peuvent désormais comprendre et afficher des informations sur les cas de test individuels.<br />
<br />
Plusieurs corrections en arrière-plan rendent le langage serveur moins intrusif : les mises à jour de configuration sont détectées immédiatement lorsque <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">tsconfig.<span style="color: #0080ff;">json</span> change</span>, les fichiers de verrouillage ne sont pas écrits pendant le « cache on save » et les directives <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">lint<span style="color: black;">-</span>ignore</span> se comportent de manière plus cohérente avec les commentaires en tête. Ces améliorations réduisent les frictions et permettent aux outils de langage de ne pas gêner l'utilisateur pendant que son travail.<br />
<br />
<b><font size="3">Exécuter CommonJS avec --require</font></b><br />
<br />
Deno v2.4 est livré avec le drapeau <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span>preload</span> qui permet de charger des fichiers avant d'exécuter le module principal, ce qui permet de personnaliser l'environnement d'exécution.<br />
<br />
Cette version ajoute le flag <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span><span style="color: #0000ff;">require</span></span> qui sert le même objectif, mais qui est destiné à l'exécution de modules CommonJS plutôt que de modules ES.<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">$ deno run <span style="color: black;">--</span><span style="color: #0000ff;">require</span> .<span style="color: black;">/</span>setup.<span style="color: #0080ff;">cjs</span> main.<span style="color: #0080ff;">ts</span></code><hr />
</div><br />
Cela rapproche Deno de la compatibilité Node.js en prenant en charge un modèle commun pour le préchargement des modules.<br />
<br />
<b><font size="3">Audit de sécurité avec deno audit</font></b><br />
<br />
L'une des nouveautés les plus importantes est la nouvelle sous-commande <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">deno audit</span>, qui aide les développeurs à identifier les failles de sécurité dans leurs dépendances en vérifiant la base de données CVE de GitHub. Cette commande analyse et génère un rapport pour les paquets JSR et npm.<br />
<br />
Pour renforcer la sécurité, Deno a également ajouté le drapeau expérimental <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">deno audit <span style="color: black;">--</span>socket</span> qui s'intègre à socket.dev :<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><table cellspacing="0" cellpadding="0"><tr><td valign="top" width="33"><div style="border: 1px dashed gray; padding-left: 5px; padding-right: 5px; margin-right: 5px; text-align: right; font-family: monospace">1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br /></div></td><td valign="top"><pre style="margin: 0">$ deno install npm<span style="color: black;">:</span>lodahs
Add npm<span style="color: black;">:</span>lodahs<span style="color: black;">@</span>0.0.1<span style="color: black;">-</span>security
&nbsp;
Dependencies<span style="color: black;">:</span>
<span style="color: black;">+</span> npm<span style="color: black;">:</span>lodahs 0.0.1<span style="color: black;">-</span>security
&nbsp;
$ deno audit <span style="color: black;">--</span>socket
&nbsp;
No known vulnerabilities found
&nbsp;
Socket.<span style="color: #0080ff;">dev</span> firewall report
&nbsp;
&#9581; pkg<span style="color: black;">:</span>npm<span style="color: black;">/</span>lodahs<span style="color: black;">@</span>0.0.1<span style="color: black;">-</span>security
&#9474; Supply Chain Risk<span style="color: black;">:</span> <span style="color: #cc66cc;">0</span>
&#9474; Maintenance<span style="color: black;">:</span> <span style="color: #cc66cc;">76</span>
&#9474; Quality<span style="color: black;">:</span> <span style="color: #cc66cc;">41</span>
&#9474; Vulnerabilities<span style="color: black;">:</span> <span style="color: #cc66cc;">100</span>
&#9474; License<span style="color: black;">:</span> <span style="color: #cc66cc;">100</span>
&#9584; Alerts <span style="color: black;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: black;">/</span><span style="color: #cc66cc;">0</span><span style="color: black;">/</span><span style="color: #cc66cc;">0</span><span style="color: black;">&#41;</span><span style="color: black;">:</span> <span style="color: black;">&#91;</span>critical<span style="color: black;">&#93;</span> malware
&nbsp;
Found <span style="color: #cc66cc;">1</span> alerts across <span style="color: #cc66cc;">1</span> packages
Severity<span style="color: black;">:</span> <span style="color: #cc66cc;">0</span> low<span style="color: black;">,</span> <span style="color: #cc66cc;">0</span> medium<span style="color: black;">,</span> <span style="color: #cc66cc;">0</span> high<span style="color: black;">,</span> <span style="color: #cc66cc;">1</span> critical</pre></td></tr></table></code><hr />
</div><br />
La commande <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">deno audit</span> analyse l'ensemble de votre graphe de dépendances, vérifie chaque paquet par rapport à la base de données CVE de GitHub et, si <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span>socket</span> est présent, par rapport à la base de données de vulnérabilités de socket.dev. Cela s'avère particulièrement utile dans les pipelines CI/CD où l'utilisateur souhaite interrompre les builds si des vulnérabilités sont détectées.<br />
<br />
Si Deno détecte la variable d'environnement <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">SOCKET_API_KEY</span>, il l'utilisera lors de ses échanges avec socket.dev afin de générer des rapports encore plus détaillés, en appliquant les politiques et les règles d'accès de l'organisation.<br />
<br />
<b><font size="3">Autres améliorations</font></b><br />
<br />
Outre les changements fondamentaux précédents, Deno 2.6 offre une nouvelle prise en charge des importations en phase source, permettant d'accéder à la source brute des modules d'une manière différente des importations standard. Parallèlement, des améliorations notables apportées au bundler renforcent la fiabilité, tandis que la compatibilité avec Node.js progresse grâce à des améliorations continues des opérations sur les fichiers, des normes cryptographiques, de la gestion des processus et des API de bases de données.<br />
<br />
Plusieurs nouvelles API et stabilisations élargissent également les possibilités offertes par la plateforme, et les utilisateurs bénéficient d'améliorations continues des performances et de nombreuses petites améliorations du flux de travail intégrées dans cette version.<br />
<br />
Pour passer à Deno 2.6, exécutez la commande suivante dans votre terminal : <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">deno upgrade</span>. Si Deno n'est pas encore installé, exécutez l'une des commandes suivantes pour l'installer :<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><table cellspacing="0" cellpadding="0"><tr><td valign="top" width="26"><div style="border: 1px dashed gray; padding-left: 5px; padding-right: 5px; margin-right: 5px; text-align: right; font-family: monospace">1<br />2<br />3<br />4<br />5<br /></div></td><td valign="top"><pre style="margin: 0"># Using Shell <span style="color: black;">&#40;</span>macOS and Linux<span style="color: black;">&#41;</span><span style="color: black;">:</span>
curl <span style="color: black;">-</span>fsSL https<span style="color: black;">:</span><span style="color: #808080;">//deno.land/install.sh | sh</span>
&nbsp;
# Using PowerShell <span style="color: black;">&#40;</span>Windows<span style="color: black;">&#41;</span><span style="color: black;">:</span>
iwr https<span style="color: black;">:</span><span style="color: #808080;">//deno.land/install.ps1 -useb | iex</span></pre></td></tr></table></code><hr />
</div><br />
<b>Source :</b> <a rel="nofollow" href="https://deno.com/blog/v2.6" target="_blank">Deno 2.6</a><br />
<br />
<b>Et vous ?</b><br />
<br />
:fleche: Quel est votre avis sur le sujet ?<br />
:fleche: Que pensez-vous des nouveautés proposées par cette version de Deno ? Les trouvez-vous utiles et intéressantes ?<br />
:fleche: Avez-vous déjà utilisé cet outil pour votre usage ou le développement d'applications, et si oui, qu'en pensez-vous ?<br />
<br />
<b>Voir aussi :</b><br />
<br />
:fleche: <a href="https://javascript.developpez.com/actu/314230/La-Version-1-9-de-Deno-le-runtime-pour-executer-JavaScript-et-TypeScript-est-disponible-elle-ameliore-les-appels-de-commande-dans-Rust-et-apporte-de-nouvelles-fonctionnalites/" target="_blank">La Version 1.9 de Deno, le runtime pour exécuter JavaScript et TypeScript, est disponible, elle améliore les appels de commande dans Rust et apporte de nouvelles fonctionnalités</a><br />
<br />
:fleche: <a href="https://javascript.developpez.com/actu/333870/Pendant-que-Deno-le-runtime-de-JS-et-TS-gagne-en-maturite-certaines-entreprises-tentent-de-l-utiliser-en-production-mais-d-autres-repartent-non-satisfaites-a-la-suite-des-tests-effectues/" target="_blank">Pendant que Deno, le runtime de JS et TS, gagne en maturité, certaines entreprises tentent de l'utiliser en production, mais d'autres repartent non satisfaites à la suite des tests effectués</a><br />
<br />
:fleche: <a href="https://javascript.developpez.com/actu/365176/Deno-contre-Oracle-Deno-a-depose-une-demande-d-annulation-de-la-marque-JavaScript-d-Oracle-Oracle-a-jusqu-au-4-janvier-2025-pour-agir-sinon-la-marque-sera-probablement-annulee/" target="_blank">Deno contre Oracle : Deno a déposé une demande d'annulation de la marque JavaScript d'Oracle, Oracle a jusqu'au 4 janvier 2025 pour agir, sinon la marque sera probablement annulée</a></div>

]]></content:encoded>
			<category domain="https://www.developpez.net/forums/f2001/javascript/typescript/">TypeScript</category>
			<dc:creator>Anthony</dc:creator>
			<guid isPermaLink="true">https://www.developpez.net/forums/d2180965/javascript/typescript/version-2-6-deno-runtime-javascript-typescript-moderne-disponible/</guid>
		</item>
		<item>
			<title>Retourner un état vrai/faux avec une function async</title>
			<link>https://www.developpez.net/forums/showthread.php?t=2180573&amp;goto=newpost</link>
			<pubDate>Fri, 21 Nov 2025 20:10:48 GMT</pubDate>
			<description><![CDATA[Bonjour à tous, 
 
J'utilise...]]></description>
			<content:encoded><![CDATA[<div>Bonjour à tous,<br />
<br />
J'utilise une fonction pour mettre à jour une valeur dans une base de donnée<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><table cellspacing="0" cellpadding="0"><tr><td valign="top" width="33"><div style="border: 1px dashed gray; padding-left: 5px; padding-right: 5px; margin-right: 5px; text-align: right; font-family: monospace">1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br /></div></td><td valign="top"><pre style="margin: 0"> <span style="color: #808080;">/* Save Chart settings */</span>
    <span style="color: #0000ff;font-weight:bold">const</span> saveChartSettings <span style="color: black;">=</span> <span style="color: #0000ff;font-weight:bold">async</span><span style="color: black;">&#40;</span>field<span style="color: black;">:</span><span style="color: #0080ff;">string</span><span style="color: black;">,</span> value<span style="color: black;">:</span><span style="color: #0080ff;">number</span><span style="color: black;">&#41;</span> <span style="color: black;">=&gt;</span> <span style="color: black;">&#123;</span>
        console.<span style="color: #0080ff;">log</span><span style="color: black;">&#40;</span> <span style="color: #FF0000;">&quot;SensorID:&quot;</span><span style="color: black;">,</span> id_sensor <span style="color: black;">,</span> <span style="color: #FF0000;">&quot;DB field:&quot;</span><span style="color: black;">,</span> field<span style="color: black;">,</span> <span style="color: #FF0000;">&quot;Value:&quot;</span><span style="color: black;">,</span>JSON.<span style="color: #0080ff;">stringify</span><span style="color: black;">&#40;</span>value<span style="color: black;">,</span><span style="color: #339933;">null</span><span style="color: black;">,</span><span style="color: #cc66cc;">1</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
        <span style="color: #0000ff;">try</span> <span style="color: black;">&#123;</span>
            <span style="color: #0000ff;font-weight:bold">const</span> response <span style="color: black;">=</span> <span style="color: #0000ff;font-weight:bold">await</span> fetch<span style="color: black;">&#40;</span><span style="color: #FF0000;">'https://api.site-site.ch/putChartSettings.inc.php'</span><span style="color: black;">,</span> <span style="color: black;">&#123;</span>
                method<span style="color: black;">:</span> <span style="color: #FF0000;">'POST'</span><span style="color: black;">,</span>
                headers<span style="color: black;">:</span><span style="color: black;">&#123;</span>
                    accept<span style="color: black;">:</span><span style="color: #FF0000;">'application(json'</span><span style="color: black;">,</span>
                    Authorisation<span style="color: black;">:</span> <span style="color: #FF0000;">'key'</span><span style="color: black;">,</span>
                <span style="color: black;">&#125;</span><span style="color: black;">,</span>
                body<span style="color: black;">:</span> JSON.<span style="color: #0080ff;">stringify</span><span style="color: black;">&#40;</span><span style="color: black;">&#123;</span>
                    id_sensor<span style="color: black;">:</span> id_sensor<span style="color: black;">,</span>
                    field<span style="color: black;">:</span> field<span style="color: black;">,</span>
                    value<span style="color: black;">:</span> value
                <span style="color: black;">&#125;</span><span style="color: black;">&#41;</span>
            <span style="color: black;">&#125;</span><span style="color: black;">&#41;</span>
&nbsp;
            <span style="color: #0000ff;">if</span><span style="color: black;">&#40;</span><span style="color: black;">!</span>response.<span style="color: #0080ff;">ok</span><span style="color: black;">&#41;</span><span style="color: black;">&#123;</span>
                setThresholdError<span style="color: black;">&#40;</span><span style="color: #FF0000;">&quot;[Save Threshold] Failed to fetch the API (check the path)&quot;</span><span style="color: black;">&#41;</span>
            <span style="color: black;">&#125;</span>
&nbsp;
            <span style="color: #0000ff;font-weight:bold">const</span> json <span style="color: black;">=</span> <span style="color: #0000ff;font-weight:bold">await</span> response.<span style="color: #0080ff;">json</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">;</span>
            console.<span style="color: #0080ff;">info</span><span style="color: black;">&#40;</span><span style="color: #FF0000;">&quot;Response:&quot;</span><span style="color: black;">,</span> json<span style="color: black;">&#41;</span><span style="color: black;">;</span>
&nbsp;
            <span style="color: #0000ff;">if</span><span style="color: black;">&#40;</span>json.<span style="color: #0080ff;">response</span><span style="color: black;">==</span><span style="color: #FF0000;">&quot;200&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#123;</span>
                <span style="color: #0000ff;">return</span> <span style="color: #cc66cc;">1</span>
            <span style="color: black;">&#125;</span>
            <span style="color: #0000ff;">else</span><span style="color: black;">&#123;</span>
               <span style="color: #0000ff;">return</span> <span style="color: #cc66cc;">0</span>
            <span style="color: black;">&#125;</span>
&nbsp;
        <span style="color: black;">&#125;</span><span style="color: #0000ff;">catch</span><span style="color: black;">&#40;</span>err<span style="color: black;">&#41;</span><span style="color: black;">&#123;</span>
            setThresholdError<span style="color: black;">&#40;</span><span style="color: #FF0000;">&quot;[Save setting] Check API path. &quot;</span> <span style="color: black;">+</span> err<span style="color: black;">&#41;</span>
        <span style="color: black;">&#125;</span> <span style="color: #0000ff;">finally</span> <span style="color: black;">&#123;</span>
&nbsp;
        <span style="color: black;">&#125;</span>
    <span style="color: black;">&#125;</span></pre></td></tr></table></code><hr />
</div><br />
<br />
Je me rends compte que j'ai besoin que la fonction me retourne 1 ou un 0 si le champs a été mis à jour, ou si aucune modification à eu lieu. Une erreur doit returner la valuer -1.<br />
<br />
Pour le moment, j'ai ajouté 'reurn 1' et 'return 0'<br />
<br />
J'ai aussi modifié ceci comme cela<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><table cellspacing="0" cellpadding="0"><tr><td valign="top" width="26"><div style="border: 1px dashed gray; padding-left: 5px; padding-right: 5px; margin-right: 5px; text-align: right; font-family: monospace">1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td valign="top"><pre style="margin: 0"><span style="color: #0000ff;">if</span><span style="color: black;">&#40;</span>saveChartSettings<span style="color: black;">&#40;</span><span style="color: #FF0000;">'border-color'</span><span style="color: black;">,</span> value<span style="color: black;">&#41;</span> <span style="color: black;">==</span> <span style="color: #cc66cc;">1</span> <span style="color: black;">&#41;</span><span style="color: black;">&#123;</span>
            setIsBorderColorSaved<span style="color: black;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: black;">&#41;</span>
        <span style="color: black;">&#125;</span>
        <span style="color: #0000ff;">else</span><span style="color: black;">&#123;</span>
            setIsBorderColorSaved<span style="color: black;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: black;">&#41;</span>
        <span style="color: black;">&#125;</span></pre></td></tr></table></code><hr />
</div><br />
Ce qui me génère une erreur<br />
<img src="https://www.developpez.net/forums/attachments/p671983d1763755692/javascript/typescript/retourner-etat-vrai-faux-function-async/screenshot-2025-11-21-at-21.07.50.png/" border="0" alt="Nom : Screenshot 2025-11-21 at 21.07.50.png
Affichages : 149
Taille : 37,0 Ko"  style="float: CONFIG" /><br />
<br />
Mon problème est que je ne sais pas comment résoudre ce problème. Je comprends qu'il manque un élément await. Mais ou?<br />
<br />
J'ai essayé ceci sans succès<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><table cellspacing="0" cellpadding="0"><tr><td valign="top" width="26"><div style="border: 1px dashed gray; padding-left: 5px; padding-right: 5px; margin-right: 5px; text-align: right; font-family: monospace">1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td valign="top"><pre style="margin: 0">if(await saveChartSettings('border-color', value) == 1 ){
            setIsBorderColorSaved(1)
        }
        else{
            setIsBorderColorSaved(0)
        }</pre></td></tr></table></code><hr />
</div><br />
je ne comprends pas aussi la ntion de Promise, je suis un peu largué.<br />
<br />
Pouvez-vous m'éclairecir?<br />
<br />
Mercii</div>


	<div style="padding:10px">

	

	
		<fieldset class="fieldset">
			<legend>Images attachées</legend>
				<div style="padding:10px">
				<img class="attach" src="https://www.developpez.net/forums/attachments/p671983d1763755692/javascript/typescript/retourner-etat-vrai-faux-function-async/screenshot-2025-11-21-at-21.07.50.png/" alt="" />&nbsp;
			</div>
		</fieldset>
	

	

	

	</div>
]]></content:encoded>
			<category domain="https://www.developpez.net/forums/f2001/javascript/typescript/">TypeScript</category>
			<dc:creator>pierrot10</dc:creator>
			<guid isPermaLink="true">https://www.developpez.net/forums/d2180573/javascript/typescript/retourner-etat-vrai-faux-function-async/</guid>
		</item>
		<item>
			<title>Microsoft annonce la version candidate de TypeScript 5.9</title>
			<link>https://www.developpez.net/forums/showthread.php?t=2178326&amp;goto=newpost</link>
			<pubDate>Wed, 30 Jul 2025 06:02:28 GMT</pubDate>
			<description>*Microsoft annonce la version...</description>
			<content:encoded><![CDATA[<div><b><font size="4">Microsoft annonce la version candidate (RC) de TypeScript 5.9 apportant des mise à jour à tsc --init ainsi que la prise en charge de import defer et de --module node20</font></b><br />
<br />
<b>Microsoft annonce la version candidate (RC) de TypeScript 5.9. TypeScript 5.9 RC apporte des mise à jour à <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">tsc <span style="color: black;">--</span>init</span>, la prise en charge de <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: #0000ff;">import</span> defer</span> et de <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span><span style="color: #0000ff;font-weight:bold">module</span> node20</span>, ainsi que des descriptions récapitulatives dans les API DOM. Par rapport à la version bêta, cette version apporte quelques corrections, notamment la restauration de <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">AbortSignal.<span style="color: #0080ff;">abort</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></span> dans la bibliothèque DOM.</b><br />
<br />
TypeScript est un langage qui s'appuie sur JavaScript en ajoutant une syntaxe pour les types. L'écriture de types dans le code permet d'expliquer l'intention et de faire vérifier le code par d'autres outils pour détecter les erreurs comme les fautes de frappe, les problèmes avec <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">null</span>et <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: #339933;">undefined</span></span>, et plus encore. Les types alimentent également les outils d'édition de TypeScript, comme l'auto-complétion, la navigation dans le code et les refactorisations que vous pouvez voir dans des éditeurs tels que Visual Studio et VS Code. En fait, TypeScript et son écosystème alimentent l'expérience JavaScript dans ces deux éditeurs également.<br />
<br />
<div style="text-align: center;"><img src="https://www.developpez.net/forums/attachments/p669087d1753860190/javascript/typescript/microsoft-annonce-version-candidate-typescript-5-9/3.jpg/" border="0" alt="Nom : 3.jpg
Affichages : 14203
Taille : 10,6 Ko"  style="float: CONFIG" /></div><br />
Voici les nouveautés de TypeScript 5.9 :<br />
<br />
<b><font size="3">tsc --init minimal et mis à jour</font></b><br />
<br />
Depuis un certain temps, le compilateur TypeScript prend en charge un indicateur <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span>init</span> qui permet de créer un fichier <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">tsconfig.<span style="color: #0080ff;">json</span></span> dans le répertoire actuel. Au cours des dernières années, l'exécution de <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">tsc <span style="color: black;">--</span>init</span> créait un fichier <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">tsconfig.<span style="color: #0080ff;">json</span></span> très « complet », rempli de paramètres commentés et de leurs descriptions.<br />
<br />
Cependant, il était courant de supprimer immédiatement la plupart du contenu de ces nouveaux fichiers <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">tsconfig.<span style="color: #0080ff;">json</span></span>. Lorsque les utilisateurs souhaitent découvrir de nouvelles options, ils s'appuient sur la fonction d'auto-complétion de leur éditeur ou qu'ils naviguent vers la référence tsconfig. La fonction de chaque paramètre est également documentée sur cette même page et peut être consultée via les infobulles/outils d'aide/informations rapides de l'éditeur. Bien que l'affichage de certains paramètres commentés puisse être utile, le fichier <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">tsconfig.<span style="color: #0080ff;">json</span></span> généré était souvent considéré comme excessif.<br />
<br />
Avec cette version, <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">tsc <span style="color: black;">--</span>init</span> s'initialise avec quelques paramètres plus prescriptifs. Parmi les points faibles courants et les désagréments rencontrés par les utilisateurs lorsqu'ils créent un nouveau projet TypeScript, on peut citer que la plupart des utilisateurs écrivent dans des modules (et non dans des scripts globaux), et <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span>moduleDetection</span> peut forcer TypeScript à traiter chaque fichier d'implémentation comme un module. Les développeurs souhaitent également souvent utiliser les dernières fonctionnalités ECMAScript directement dans leur runtime, de sorte que <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span>target</span> peut généralement être défini sur <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">esnext</span>. Les utilisateurs de JSX trouvent souvent que revenir à <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span>jsx</span> est une friction inutile, et ses options sont légèrement déroutantes. Et souvent, les projets finissent par charger plus de fichiers de déclaration depuis TypeScript n'en a réellement besoin, mais spécifier un tableau de <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">types</span> vide peut aider à limiter cela.<br />
<br />
Dans TypeScript 5.9, un simple <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">tsc <span style="color: black;">--</span>init</span> sans autre indicateur générera le fichier <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">tsconfig.<span style="color: #0080ff;">json</span></span> suivant :<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><table cellspacing="0" cellpadding="0"><tr><td valign="top" width="33"><div style="border: 1px dashed gray; padding-left: 5px; padding-right: 5px; margin-right: 5px; text-align: right; font-family: monospace">1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br /></div></td><td valign="top"><pre style="margin: 0"><span style="color: black;">&#123;</span>
  <span style="color: #808080;">// Visit https://aka.ms/tsconfig to read more about this file</span>
  <span style="color: #FF0000;">&quot;compilerOptions&quot;</span><span style="color: black;">:</span> <span style="color: black;">&#123;</span>
    <span style="color: #808080;">// File Layout</span>
    <span style="color: #808080;">// &quot;rootDir&quot;: &quot;./src&quot;,</span>
    <span style="color: #808080;">// &quot;outDir&quot;: &quot;./dist&quot;,</span>
&nbsp;
    <span style="color: #808080;">// Environment Settings</span>
    <span style="color: #808080;">// See also https://aka.ms/tsconfig_modules</span>
    <span style="color: #FF0000;">&quot;module&quot;</span><span style="color: black;">:</span> <span style="color: #FF0000;">&quot;nodenext&quot;</span><span style="color: black;">,</span>
    <span style="color: #FF0000;">&quot;target&quot;</span><span style="color: black;">:</span> <span style="color: #FF0000;">&quot;esnext&quot;</span><span style="color: black;">,</span>
    <span style="color: #FF0000;">&quot;types&quot;</span><span style="color: black;">:</span> <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><span style="color: black;">,</span>
    <span style="color: #808080;">// For nodejs:</span>
    <span style="color: #808080;">// &quot;lib&quot;: [&quot;esnext&quot;],</span>
    <span style="color: #808080;">// &quot;types&quot;: [&quot;node&quot;],</span>
    <span style="color: #808080;">// and npm install -D @types/node</span>
&nbsp;
    <span style="color: #808080;">// Other Outputs</span>
    <span style="color: #FF0000;">&quot;sourceMap&quot;</span><span style="color: black;">:</span> <span style="color: #339933;">true</span><span style="color: black;">,</span>
    <span style="color: #FF0000;">&quot;declaration&quot;</span><span style="color: black;">:</span> <span style="color: #339933;">true</span><span style="color: black;">,</span>
    <span style="color: #FF0000;">&quot;declarationMap&quot;</span><span style="color: black;">:</span> <span style="color: #339933;">true</span><span style="color: black;">,</span>
&nbsp;
    <span style="color: #808080;">// Stricter Typechecking Options</span>
    <span style="color: #FF0000;">&quot;noUncheckedIndexedAccess&quot;</span><span style="color: black;">:</span> <span style="color: #339933;">true</span><span style="color: black;">,</span>
    <span style="color: #FF0000;">&quot;exactOptionalPropertyTypes&quot;</span><span style="color: black;">:</span> <span style="color: #339933;">true</span><span style="color: black;">,</span>
&nbsp;
    <span style="color: #808080;">// Style Options</span>
    <span style="color: #808080;">// &quot;noImplicitReturns&quot;: true,</span>
    <span style="color: #808080;">// &quot;noImplicitOverride&quot;: true,</span>
    <span style="color: #808080;">// &quot;noUnusedLocals&quot;: true,</span>
    <span style="color: #808080;">// &quot;noUnusedParameters&quot;: true,</span>
    <span style="color: #808080;">// &quot;noFallthroughCasesInSwitch&quot;: true,</span>
    <span style="color: #808080;">// &quot;noPropertyAccessFromIndexSignature&quot;: true,</span>
&nbsp;
    <span style="color: #808080;">// Recommended Options</span>
    <span style="color: #FF0000;">&quot;strict&quot;</span><span style="color: black;">:</span> <span style="color: #339933;">true</span><span style="color: black;">,</span>
    <span style="color: #FF0000;">&quot;jsx&quot;</span><span style="color: black;">:</span> <span style="color: #FF0000;">&quot;react-jsx&quot;</span><span style="color: black;">,</span>
    <span style="color: #FF0000;">&quot;verbatimModuleSyntax&quot;</span><span style="color: black;">:</span> <span style="color: #339933;">true</span><span style="color: black;">,</span>
    <span style="color: #FF0000;">&quot;isolatedModules&quot;</span><span style="color: black;">:</span> <span style="color: #339933;">true</span><span style="color: black;">,</span>
    <span style="color: #FF0000;">&quot;noUncheckedSideEffectImports&quot;</span><span style="color: black;">:</span> <span style="color: #339933;">true</span><span style="color: black;">,</span>
    <span style="color: #FF0000;">&quot;moduleDetection&quot;</span><span style="color: black;">:</span> <span style="color: #FF0000;">&quot;force&quot;</span><span style="color: black;">,</span>
    <span style="color: #FF0000;">&quot;skipLibCheck&quot;</span><span style="color: black;">:</span> <span style="color: #339933;">true</span><span style="color: black;">,</span>
  <span style="color: black;">&#125;</span>
<span style="color: black;">&#125;</span></pre></td></tr></table></code><hr />
</div><br />
<br />
<b><font size="3">Prise en charge de import defer</font></b><br />
<br />
TypeScript 5.9 introduit la prise en charge de la proposition d'évaluation différée des modules ECMAScript à l'aide de la nouvelle syntaxe <b>import defer</b>. Cette fonctionnalité vous permet d'importer un module sans exécuter immédiatement le module et ses dépendances, ce qui vous offre un meilleur contrôle sur le moment où le travail et les effets secondaires se produisent.<br />
<br />
La syntaxe n'autorise que les importations d'espaces de noms :<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><span style="color: #0000ff;">import</span> defer <span style="color: black;">*</span> <span style="color: #0000ff;font-weight:bold">as</span> feature <span style="color: #0000ff;">from</span> <span style="color: #FF0000;">&quot;./some-feature.js&quot;</span><span style="color: black;">;</span></code><hr />
</div><br />
<br />
Le principal avantage de <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: #0000ff;">import</span> defer</span> est que le module n'est évalué que lors de sa première utilisation. Prenons l'exemple suivant :<br />
<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><table cellspacing="0" cellpadding="0"><tr><td valign="top" width="33"><div style="border: 1px dashed gray; padding-left: 5px; padding-right: 5px; margin-right: 5px; text-align: right; font-family: monospace">1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td valign="top"><pre style="margin: 0"><span style="color: #808080;">// ./some-feature.ts</span>
initializationWithSideEffects<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">;</span>
&nbsp;
<span style="color: #0000ff;font-weight:bold">function</span> initializationWithSideEffects<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: black;">&#123;</span>
  <span style="color: #808080;">// ...</span>
  specialConstant <span style="color: black;">=</span> <span style="color: #cc66cc;">42</span><span style="color: black;">;</span>
&nbsp;
  console.<span style="color: #0080ff;">log</span><span style="color: black;">&#40;</span><span style="color: #FF0000;">&quot;Side effects have occurred!&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">;</span>
<span style="color: black;">&#125;</span>
&nbsp;
<span style="color: #0000ff;font-weight:bold">export</span> <span style="color: #0000ff;font-weight:bold">let</span> specialConstant<span style="color: black;">:</span> <span style="color: #0080ff;">number</span><span style="color: black;">;</span></pre></td></tr></table></code><hr />
</div><br />
<br />
Lorsque vous utilisez <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: #0000ff;">import</span> defer</span>, la fonction <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">initializationWithSideEffects<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></span> ne sera pas appelée tant que vous n'aurez pas accédé à une propriété de l'espace de noms importé :<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><table cellspacing="0" cellpadding="0"><tr><td valign="top" width="26"><div style="border: 1px dashed gray; padding-left: 5px; padding-right: 5px; margin-right: 5px; text-align: right; font-family: monospace">1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td valign="top"><pre style="margin: 0"><span style="color: #0000ff;">import</span> defer <span style="color: black;">*</span> <span style="color: #0000ff;font-weight:bold">as</span> feature <span style="color: #0000ff;">from</span> <span style="color: #FF0000;">&quot;./some-feature.js&quot;</span><span style="color: black;">;</span>
&nbsp;
<span style="color: #808080;">// No side effects have occurred yet</span>
&nbsp;
<span style="color: #808080;">// ...</span>
&nbsp;
<span style="color: #808080;">// As soon as `specialConstant` is accessed, the contents of the `feature`</span>
<span style="color: #808080;">// module are run and side effects have taken place.</span>
console.<span style="color: #0080ff;">log</span><span style="color: black;">&#40;</span>feature.<span style="color: #0080ff;">specialConstant</span><span style="color: black;">&#41;</span><span style="color: black;">;</span> <span style="color: #808080;">// 42</span></pre></td></tr></table></code><hr />
</div><br />
<br />
Comme l'évaluation du module est différée jusqu'à ce que vous accédiez à un membre du module, vous ne pouvez pas utiliser d'importations nommées ou d'importations par défaut avec <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: #0000ff;">import</span> defer</span> :<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><table cellspacing="0" cellpadding="0"><tr><td valign="top" width="26"><div style="border: 1px dashed gray; padding-left: 5px; padding-right: 5px; margin-right: 5px; text-align: right; font-family: monospace">1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td valign="top"><pre style="margin: 0"><span style="color: #808080;">//  Not allowed</span>
<span style="color: #0000ff;">import</span> defer <span style="color: black;">&#123;</span> doSomething <span style="color: black;">&#125;</span> <span style="color: #0000ff;">from</span> <span style="color: #FF0000;">&quot;some-module&quot;</span><span style="color: black;">;</span>
&nbsp;
<span style="color: #808080;">//  Not allowed  </span>
<span style="color: #0000ff;">import</span> defer defaultExport <span style="color: #0000ff;">from</span> <span style="color: #FF0000;">&quot;some-module&quot;</span><span style="color: black;">;</span>
&nbsp;
<span style="color: #808080;">//  Only this syntax is supported</span>
<span style="color: #0000ff;">import</span> defer <span style="color: black;">*</span> <span style="color: #0000ff;font-weight:bold">as</span> feature <span style="color: #0000ff;">from</span> <span style="color: #FF0000;">&quot;some-module&quot;</span><span style="color: black;">;</span></pre></td></tr></table></code><hr />
</div><br />
<br />
Notez que lorsque vous écrivez <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: #0000ff;">import</span> defer</span>, le module et ses dépendances sont entièrement chargés et prêts à être exécutés. Cela signifie que le module doit exister et sera chargé à partir du système de fichiers ou d'une ressource réseau. La principale différence entre <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: #0000ff;">import</span></span> normale et <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: #0000ff;">import</span> difer</span> réside dans le fait que l'exécution des instructions et des déclarations est différée jusqu'à ce que vous accédiez à une propriété de l'espace de noms importé.<br />
<br />
Cette fonctionnalité est particulièrement utile pour charger de manière conditionnelle des modules dont l'initialisation est coûteuse ou spécifique à une plateforme. Elle peut également améliorer les performances de démarrage en différant l'évaluation des modules pour les fonctionnalités de l'application jusqu'à ce qu'elles soient réellement nécessaires.<br />
<br />
Notez que <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: #0000ff;">import</span> defer</span> n'est pas transformé ou « déclassé » par TypeScript. Il est destiné à être utilisé dans des environnements d'exécution qui prennent en charge cette fonctionnalité de manière native, ou par des outils tels que des bundlers qui peuvent appliquer la transformation appropriée. Cela signifie que <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: #0000ff;">import</span> defer</span> ne fonctionnera que sous les modes <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span><span style="color: #0000ff;font-weight:bold">module</span></span> <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">preserve</span> et <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">esnext</span>.<br />
<br />
<b><font size="3">Prise en charge de --module node20</font></b><br />
<br />
TypeScript fournit plusieurs options <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">node<span style="color: black;">*</span></span> pour les paramètres <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span><span style="color: #0000ff;font-weight:bold">module</span></span> et <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span>moduleResolution</span>. Plus récemment, <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span><span style="color: #0000ff;font-weight:bold">module</span> nodenext</span> a pris en charge la possibilité de <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">requ&eacute;rir <span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></span> des modules ECMAScript à partir de modules CommonJS, et rejette correctement les assertions d'importation (au profit des attributs d'importation liés aux normes).<br />
<br />
TypeScript 5.9 apporte une option stable pour ces paramètres appelée <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">node20</span>, destinée à modéliser le comportement de Node.js v20. Contrairement à <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span><span style="color: #0000ff;font-weight:bold">module</span> nodenext</span> ou <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span>moduleResolution nodenext</span>, cette option ne devrait pas connaître de nouveaux comportements à l'avenir. Contrairement à <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">nodenext</span>, la spécification de <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span><span style="color: #0000ff;font-weight:bold">module</span> node20</span> implique <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span>target es2023</span>, sauf configuration contraire. <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span><span style="color: #0000ff;font-weight:bold">module</span> nodenext</span>, en revanche, implique le <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">--</span>target esnext flottant</span>.<br />
<br />
<b><font size="3">Descriptions sommaires dans les API DOM</font></b><br />
<br />
Auparavant, la plupart des API DOM dans TypeScript renvoyaient uniquement vers la documentation MDN de l'API. Ces liens étaient utiles, mais ils ne fournissaient pas de résumé rapide du fonctionnement de l'API. Grâce à quelques modifications, TypeScript inclut désormais des descriptions sommaires pour de nombreuses API DOM basées sur la documentation MDN.<br />
<br />
<b><font size="3">Info-bulles extensibles (aperçu)</font></b><br />
<br />
Les infobulles (également appelées « info-bulles de l'éditeur » et « info-bulles ») peuvent être très utiles pour consulter les variables afin de connaître leur type, ou les alias de type afin de savoir à quoi ils font référence. Cependant, il est courant que les utilisateurs souhaitent approfondir leurs connaissances et obtenir des détails sur ce qui est affiché dans l'info-bulle. Par exemple, si nous passons la souris sur le paramètre <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">options</span> dans l'exemple suivant :<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><span style="color: #0000ff;font-weight:bold">export</span> <span style="color: #0000ff;font-weight:bold">function</span> drawButton<span style="color: black;">&#40;</span>options<span style="color: black;">:</span> Options<span style="color: black;">&#41;</span><span style="color: black;">:</span> <span style="color: #0080ff;">void</span></code><hr />
</div><br />
<br />
Nous obtenons <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">&#40;</span>parameter<span style="color: black;">&#41;</span> options<span style="color: black;">:</span> Options</span>.<br />
<br />
<div style="text-align: center;"><img src="https://www.developpez.net/forums/attachments/p669085d1753859704/javascript/typescript/microsoft-annonce-version-candidate-typescript-5-9/1.jpg/" border="0" alt="Nom : 1.jpg
Affichages : 1768
Taille : 14,6 Ko"  style="float: CONFIG" /></div><br />
Pour vous aider, TypeScript 5.9 propose désormais en avant-première une fonctionnalité appelée « expandable hovers » (survols extensibles) ou « quick info verbosity » (verbosité des informations rapides). Si vous utilisez un éditeur tel que VS Code, vous verrez désormais un bouton <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">+</span></span> et <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">-</span></span> à gauche de ces infobulles. Cliquer sur le bouton <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">+</span></span> permettra d'afficher les types de manière plus détaillée, tandis que cliquer sur le bouton - vous ramènera à la vue précédente.<br />
<br />
<div style="text-align: center;"><img src="https://www.developpez.net/forums/attachments/p669086d1753859708/javascript/typescript/microsoft-annonce-version-candidate-typescript-5-9/2.jpg/" border="0" alt="Nom : 2.jpg
Affichages : 1771
Taille : 26,8 Ko"  style="float: CONFIG" /></div><br />
<b><font size="3">Longueur maximale configurable des infobulles</font></b><br />
<br />
Il arrive parfois que les info-bulles soient si longues que TypeScript les tronque pour les rendre plus lisibles. L'inconvénient est que les informations les plus importantes sont souvent omises de l'info-bulle, ce qui peut être frustrant. Pour remédier à cela, le serveur de langage de TypeScript 5.9 prend en charge une durée d'affichage configurable, qui peut être définie dans VS Code via le paramètre <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">js<span style="color: black;">/</span>ts.<span style="color: #0080ff;">hover</span>.<span style="color: #0080ff;">maximumLength</span></span>.<br />
<br />
De plus, la nouvelle longueur par défaut est nettement supérieure à la précédente. Cela signifie que dans TypeScript 5.9, vous devriez voir plus d'informations dans vos info-bulles par défaut.<br />
<br />
<b><font size="3">Optimisations</font></b><br />
<br />
<b>Instantiations de cache sur les mappeurs</b><br />
<br />
Lorsque TypeScript remplace les paramètres de type par des arguments de type spécifiques, il peut finir par instancier à plusieurs reprises de nombreux types intermédiaires identiques. Dans des bibliothèques complexes telles que Zod et tRPC, cela peut entraîner à la fois des problèmes de performances et des erreurs liées à une profondeur d'instanciation de type excessive. Grâce à une modification apportée par Mateusz Burzy&#324;ski, TypeScript 5.9 est capable de mettre en cache de nombreuses instanciations intermédiaires lorsque le travail a déjà commencé sur une instanciation de type spécifique. Cela permet d'éviter beaucoup de travail et d'allocations inutiles.<br />
<br />
<b>Éviter la création de fermetures dans <i>fileOrDirectoryExistsUsingSource</i></b><br />
<br />
En JavaScript, une expression de fonction alloue généralement un nouvel objet de fonction, même si la fonction wrapper se contente de transmettre des arguments à une autre fonction sans capturer de variables. Dans les chemins de code autour des vérifications d'existence de fichiers, l'équipe de Microsoft a trouvé des exemples de ces appels de fonction de transmission, même si les fonctions sous-jacentes ne prenaient qu'un seul argument. Compte tenu du nombre de vérifications d'existence pouvant avoir lieu dans des projets plus importants, ils ont cité une accélération d'environ 11 %.<br />
<br />
<b><font size="3">Changements comportementaux notables</font></b><br />
<br />
<b>Modifications de lib.d.ts</b><br />
<br />
Les types générés pour le DOM peuvent avoir un impact sur la vérification des types de votre base de code.<br />
<br />
De plus, un changement notable est que <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">ArrayBuffer</span> a été modifié de telle sorte qu'il n'est plus un supertype de plusieurs types <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">TypedArray</span> différents. Cela inclut également les sous-types de <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">UInt8Array</span>, tels que <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">Buffer</span> de Node.js. En conséquence, vous verrez apparaître de nouveaux messages d'erreur tels que :<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><table cellspacing="0" cellpadding="0"><tr><td valign="top" width="26"><div style="border: 1px dashed gray; padding-left: 5px; padding-right: 5px; margin-right: 5px; text-align: right; font-family: monospace">1<br />2<br />3<br />4<br />5<br /></div></td><td valign="top"><pre style="margin: 0">error TS2345<span style="color: black;">:</span> Argument <span style="color: #0000ff;font-weight:bold">of</span> <span style="color: #0000ff;font-weight:bold">type</span> <span style="color: #FF0000;">'ArrayBufferLike'</span> <span style="color: #0080ff;">is</span> not assignable to parameter <span style="color: #0000ff;font-weight:bold">of</span> <span style="color: #0000ff;font-weight:bold">type</span> <span style="color: #FF0000;">'BufferSource'</span>.
<span style="color: #0080ff;">error</span> TS2322<span style="color: black;">:</span> Type <span style="color: #FF0000;">'ArrayBufferLike'</span> <span style="color: #0080ff;">is</span> not assignable to <span style="color: #0000ff;font-weight:bold">type</span> <span style="color: #FF0000;">'ArrayBuffer'</span>.
<span style="color: #0080ff;">error</span> TS2322<span style="color: black;">:</span> Type <span style="color: #FF0000;">'Buffer'</span> <span style="color: #0080ff;">is</span> not assignable to <span style="color: #0000ff;font-weight:bold">type</span> <span style="color: #FF0000;">'Uint8Array&lt;ArrayBufferLike&gt;'</span>.
<span style="color: #0080ff;">error</span> TS2322<span style="color: black;">:</span> Type <span style="color: #FF0000;">'Buffer'</span> <span style="color: #0080ff;">is</span> not assignable to <span style="color: #0000ff;font-weight:bold">type</span> <span style="color: #FF0000;">'ArrayBuffer'</span>.
<span style="color: #0080ff;">error</span> TS2345<span style="color: black;">:</span> Argument <span style="color: #0000ff;font-weight:bold">of</span> <span style="color: #0000ff;font-weight:bold">type</span> <span style="color: #FF0000;">'Buffer'</span> <span style="color: #0080ff;">is</span> not assignable to parameter <span style="color: #0000ff;font-weight:bold">of</span> <span style="color: #0000ff;font-weight:bold">type</span> <span style="color: #FF0000;">'string | Uint8Array&lt;ArrayBufferLike&gt;'</span>.</pre></td></tr></table></code><hr />
</div><br />
<br />
Si vous rencontrez des problèmes avec <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">Buffer</span>, vous pouvez d'abord vérifier que vous utilisez la dernière version du package <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block"><span style="color: black;">@</span>types<span style="color: black;">/</span>node</span>. Cela peut impliquer d'exécuter<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">npm update <span style="color: black;">@</span>types<span style="color: black;">/</span>node <span style="color: black;">--</span>save<span style="color: black;">-</span>dev</code><hr />
</div><br />
<br />
La plupart du temps, la solution consiste à spécifier un type de tampon sous-jacent plus précis au lieu d'utiliser le type <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">ArrayBufferLike</span> par défaut (c'est-à-dire en écrivant explicitement <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">Uint8Array<span style="color: black;">&lt;</span>ArrayBuffer<span style="color: black;">&gt;</span></span> plutôt que simplement <span style="font-family: monospace; padding: 2px; background: #ddd; display: inline-block">Uint8Array</span>).<br />
<br />
<b><font size="3">Modifications de l'inférence des arguments de type</font></b><br />
<br />
Afin de corriger les « fuites » de variables de type lors de l'inférence, TypeScript 5.9 pourrait introduire des modifications dans les types et éventuellement de nouvelles erreurs dans certaines bases de code. Celles-ci sont difficiles à prévoir, mais peuvent souvent être corrigées en ajoutant des arguments de type aux appels de fonctions génériques. <br />
<br />
<b><font size="3">La suite ?</font></b><br />
<br />
Récemment, Microsoft s'est concentré sur le portage natif de TypeScript, qui sera finalement disponible sous le nom de TypeScript 7. Pour rappel, en mars, <a href="https://typescript.developpez.com/actu/369976/Un-TypeScript-10x-plus-rapide-Anders-Hejlsberg-architecte-principal-de-Microsoft-pour-TypeScript-presente-un-nouveau-portage-de-TypeScript-qui-offrira-aux-developpeurs-un-outil-de-haute-performance/" target="_blank">Microsoft a annoncé une réécriture de son langage de programmation TypeScript en le dotant d'un compilateur et d'un ensemble d'outils natifs</a>. Cet effort vise à résoudre les problèmes de performance, en particulier dans les grandes bases de code, en portant le compilateur TypeScript existant de TypeScript/JavaScript au langage natif, Go.<br />
<br />
Selon Anders Hejlsberg, architecte principal de Microsoft pour TypeScript, &quot;<i>l'implémentation native améliorera considérablement le démarrage de l'éditeur, divisera par 10 la plupart des temps de construction et réduira substantiellement l'utilisation de la mémoire</i>&quot;. Avec la sortie de TypeScript 5.9 RC, Microsoft annonce que vous pouvez déjà essayer le portage natif en consultant les aperçus natifs de TypeScript, qui sont publiés.<br />
<br />
Étant donné que peu de choses ont changé depuis la version bêta de TypeScript 5.9, Microsoft prévoit de publier TypeScript 5.9 en tant que version candidate finale pour début août. <br />
<br />
<b>Source</b> : <a rel="nofollow" href="https://devblogs.microsoft.com/typescript/announcing-typescript-5-9-rc/" target="_blank">Annonce de Microsoft</a><br />
<br />
<b>Et vous ?</b><br />
<br />
:fleche: Pensez-vous que ces améliorationts sont crédibles ou pertinentes ?<br />
:fleche: Quel est votre avis sur cette version ?<br />
<br />
<b>Voir aussi :</b><br />
<br />
:fleche: <a href="https://typescript.developpez.com/actu/369721/Microsoft-annonce-la-disponibilite-de-TypeScript-5-8-apportant-des-verifications-plus-granulaires-pour-les-branches-dans-les-expressions-de-retour-ainsi-que-plusieurs-autres-ameliorations/" target="_blank">Microsoft annonce la disponibilité de TypeScript 5.8, apportant des vérifications plus granulaires pour les branches dans les expressions de retour, ainsi que plusieurs autres améliorations</a><br />
<br />
:fleche: <a href="https://typescript.developpez.com/actu/368264/A-partir-de-la-version-23-6-0-Node-js-prend-en-charge-TypeScript-par-defaut-en-raison-de-sa-popularite-croissante-TypeScript-etant-la-fonctionnalite-la-plus-demandee-sur-Node-js/" target="_blank">À partir de la version 23.6.0, Node.js prend en charge TypeScript par défaut, en raison de sa popularité croissante. TypeScript étant la fonctionnalité la plus demandée sur Node.js</a><br />
<br />
:fleche: <a href="https://jetbrains.developpez.com/actu/371385/WebStorm-2025-1-est-disponible-avec-une-meilleure-prise-en-charge-d-Angular-et-des-monorepos-et-bien-d-autres-nouveautes-et-ameliorations/" target="_blank">WebStorm 2025.1 est disponible avec une meilleure prise en charge d'Angular et des monorepos et bien d'autres nouveautés et améliorations</a></div>


	<div style="padding:10px">

	

	
		<fieldset class="fieldset">
			<legend>Images attachées</legend>
				<div style="padding:10px">
				<img class="attach" src="https://www.developpez.net/forums/attachments/p669085d1753859704/javascript/typescript/microsoft-annonce-version-candidate-typescript-5-9/1.jpg/" alt="" />&nbsp;<img class="attach" src="https://www.developpez.net/forums/attachments/p669086d1753859708/javascript/typescript/microsoft-annonce-version-candidate-typescript-5-9/2.jpg/" alt="" />&nbsp;<img class="attach" src="https://www.developpez.net/forums/attachments/p669087d1753860190/javascript/typescript/microsoft-annonce-version-candidate-typescript-5-9/3.jpg/" alt="" />&nbsp;
			</div>
		</fieldset>
	

	

	

	</div>
]]></content:encoded>
			<category domain="https://www.developpez.net/forums/f2001/javascript/typescript/">TypeScript</category>
			<dc:creator>Jade Emy</dc:creator>
			<guid isPermaLink="true">https://www.developpez.net/forums/d2178326/javascript/typescript/microsoft-annonce-version-candidate-typescript-5-9-a/</guid>
		</item>
	</channel>
</rss>
