New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix type error of tagged template literal in TypeScript 2.9 #1777

Closed
wants to merge 2 commits into
base: master
from

Conversation

Projects
None yet
2 participants
@utatti

utatti commented Jun 1, 2018

With TypeScript 2.9, we can provide type arguments to tagged template literals.

It means that we no more need extra library for typing ThemedStyledFunction.

const withTypeArgs = styled.h1<{ hello: string }>`
  color: ${props => props.hello};
`;

However, with the current typings, an error occurs:

image

The reason is that ThemedStyledFunction has overridden function types in a wrong order.

interface ThemedStyledFunction<P, T, O = P> {
  (...): StyledComponentClass<P, T, O>;
  <U>(...): StyledComponentClass<P, T, O>;

  ...
}

When doing like above, the first type is applied, so type argument is not actually used and the error occurs. To fix this, we can just change the order, but I think using a default type argument is better.

interface ThemedStyledFunction<P, T, O = P> {
  <U = {}>(...): StyledComponentClass<P, T, O>;

  ...
}

I've also added a test case for this. Please let me know if there is anything unclear.

@utatti utatti changed the title from Use TypeScript 2.9 template literal to Use TypeScript 2.9 for tagged template literal with typings Jun 1, 2018

@utatti utatti changed the title from Use TypeScript 2.9 for tagged template literal with typings to Fix type error in tagged template literal with typings Jun 1, 2018

@utatti utatti force-pushed the utatti:ts-2.9-template-literal branch from 3bb8dfa to 480b7d2 Jun 2, 2018

@utatti

This comment has been minimized.

utatti commented Jun 2, 2018

Rebased with master to fix CI failure.

@utatti utatti changed the title from Fix type error in tagged template literal with typings to Fix type error of tagged template literal in TypeScript 2.9 Jun 2, 2018

@probablyup

This comment has been minimized.

Contributor

probablyup commented Jun 2, 2018

@Igorbek is this safe to merge as a minor release? nvm just noticed the TS 2.9 bump. Nope.

@probablyup probablyup requested review from Igorbek and removed request for Igorbek Jun 2, 2018

@probablyup

This comment has been minimized.

Contributor

probablyup commented Jun 2, 2018

Please see #1778. Moving TS types out of this repo and would be great for you to contribute this fix to DefinitelyTyped when it's moved over.

@probablyup probablyup closed this Jun 2, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment