Targeting ES5 with TypeScript in Visual Studio

This has changed with TypeScript 0.8.2. You now change TypeScriptTarget in the .csproj file from: <TypeScriptTarget>ES3</TypeScriptTarget> to <TypeScriptTarget>ES5</TypeScriptTarget> MyApp.csproj: <PropertyGroup Condition=”‘$(Configuration)’ == ‘Debug'”> <TypeScriptTarget>ES5</TypeScriptTarget> <TypeScriptIncludeComments>true</TypeScriptIncludeComments> <TypeScriptSourceMap>true</TypeScriptSourceMap> <TypeScriptModuleKind>AMD</TypeScriptModuleKind> </PropertyGroup> <PropertyGroup Condition=”‘$(Configuration)’ == ‘Release'”> <TypeScriptTarget>ES5</TypeScriptTarget> <TypeScriptIncludeComments>false</TypeScriptIncludeComments> <TypeScriptSourceMap>false</TypeScriptSourceMap> <TypeScriptModuleKind>AMD</TypeScriptModuleKind> </PropertyGroup> See also Asher Barak answer

Property ‘dataset’ does not exist on type ‘EventTarget’

Problem is here Element, document, and window can be an EventTarget. You should detect your EventTarget if is an element. So in your case below code should work linkProvider = (ev: React.SyntheticEvent<EventTarget>) => { // If event target not an HTMLButtonElement, exit if (!(ev.target instanceof HTMLButtonElement)) { return; } console.debug(‘ev.target’, ev.target.dataset[‘ix’]) } In the short … Read more

Proper way to declare JSON object in Typescript

Here is an easy and naive implementation of what you’re asking for: interface IDataNode { id: number; title: string; node: Array<IDataNode>; } If you want to instantiate said nodes from code: class DataNode implements IDataNode { id: number; title: string; node: Array<IDataNode>; constructor(id: number, title: string, node?: Array<IDataNode>) { this.id = id; this.title = title; … Read more

Why am I getting “Unexpected token import” on one webpack project but not the other?

I had a similar issue where I was using async\await and Promises (both ES6 constructs) using the import keyword in the ts source files to import other ts modules. I could transpile with TypeScript using the default js target version (ES5) which produces transpile errors complaining about the async\await and Promise keywords but since I’m … Read more

Is there a way to define type for array with unique items in typescript?

The only possible way this could work at compile time is if your arrays are tuples composed of literals. For example, here are some arrays with the same runtime values, but with different types in TypeScript: const tupleOfLiterals: [1, 2, 2] = [1, 2, 2]; const tupleOfNonLiterals: [number, number, number] = [1, 2, 2]; const … Read more

Platform specific import component in react native with typescript

One way of doing it, which is a bit annoying, is creating a declaration file with the same name. component – component.d.ts <— – component.android.tsx – component.ios.tsx then import { file } from “../group/file”; Update: Another way of doing it is just omit the extension for one of them, then typescript will pick up the … Read more

How to properly type the _document.tsx file from Next.js?

This is what I’ve ended up doing to type the getInitialProps and render methods: import React, { ReactElement } from “react”; import Document, { DocumentInitialProps, DocumentContext } from ‘next/document’; export default class MyDocument extends Document { static async getInitialProps(ctx: DocumentContext): Promise<DocumentInitialProps> { // … } render(): ReactElement { return( // … ); } } https://github.com/vercel/next.js/blob/canary/examples/with-styled-components/pages/_document.js … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)