Skip to content

Cannot return unique symbol #32242

Closed
Closed
@AnyhowStep

Description

@AnyhowStep

TypeScript Version: 3.5.1

Search Terms:

function, return type, unique symbol

Code

const a = Symbol();
const b = Symbol();

function identity<T> (t : T) : T {
  return t;
}

/**
 * Mouseover `identity(a)`,
 * Tooltip shows,
 * 
 * ```
 * function identity<typeof a>(t: typeof a): typeof a
 * ```
 */
/**
 * Expected : typeof a
 * 
 * Actual   : symbol
 */
const actual = identity(a);
/**
 * Error
 * 
 * Type 'symbol' is not assignable to type 'unique symbol'.
 */
const expectA : typeof a = actual;

/////////////////////////////////////////////////

function giveTypeOfA () : typeof a {
  return a;
}

/**
 * Expected : typeof a
 * 
 * Actual   : symbol
 */
const actual2 = giveTypeOfA();
/**
 * Error
 * 
 * Type 'symbol' is not assignable to type 'unique symbol'.
 */
const expectA2 : typeof a = actual2;

Expected behavior:

actual and actual2 should be typeof a

Actual behavior:

actual and actual2 are symbol

Playground Link: Playground

Related Issues:

The very last comment of #24506 asks a question about intended behaviour but it goes unanswered.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions