Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

$ExpectType did not unwrap the type alias #57

Open
ikatyang opened this issue Aug 17, 2017 · 1 comment
Open

$ExpectType did not unwrap the type alias #57

ikatyang opened this issue Aug 17, 2017 · 1 comment

Comments

@ikatyang
Copy link

This is just a minimal repro, the real use case is for types/npm-ramda to generate DT compatible tests so that we could put them on DT, but we got problems.

Is there any reason we can't pass the enclosingDeclaration parameter to typeToString in the expect rule?

Code

(index.d.ts)

export type Or<T, U> = T | U;

(something-tests.ts)

import * as something from 'something';

declare const result: something.Or<string, number>;

// $ExpectType string | number
result;

Expected

no errors

Actual

ERROR: 6:1   expect   Expected type to be:
  string | number
got:
  Or<string, number>
@danvk
Copy link

danvk commented Jan 5, 2019

Or even more ridiculous:

ERROR: 299:1  expect                      Expected type to be:
  'Point'
got:
  "Point"

The solution being to change single quotes to double quotes.

The root issue here is that dtslint just does a comparison on the string representation of the types:https://github.com/Microsoft/dtslint/blob/4539c93657ea93e96eff84aa835422f6eed3e3b7/src/rules/expectRule.ts#L297-L304

The solution is to change the check to use the type relationships API. It should at least be isIdenticalTo rather than a string comparison. (Update: that PR got closed, not merged, so this is block on TypeScript having a type relationships API.)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants