microsoft / microsoft/TypeScript

Error output: Don't deep compare to native objects

Open
#26,986 3 comments 0 reactions 1 assignee View on GitHub

@DanielRosenwasser is already working on this.

Since Oct 9, 2018.

Committed Domain: Error Messages Rescheduled Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

TypeScript Version: 3.1.0-dev.201xxxxx

Search Terms:

Currently if we assign not assignable type to a variable, ts shows a deep 'not assignable' error with mark all not compatible fields. Even for a native objects like Array, Promise, Date etc...
But I think this is too noisily. All I want to know is that my type in not assignable to Array. Don't try to compare guts of Array with my type.

Code

type A = {a: string}
var y:A = {a: ''}
var x0: string = y; // Type 'A' is not assignable to type 'string'.  -- it's ok!
var x1: A[]  = y; // Property 'length' is missing in type 'A'.
var x2: Promise<A> = y; // Property 'then' is missing in type 'A'.
var x3: Date = y; // Property 'toDateString' is missing in type 'A'.
var x4: Node = y; // Property 'baseURI' is missing in type 'A'.

Expected behavior:

Actual behavior:

Playground Link:

Related Issues:

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.